How to Download JDK and Export Java Home for Test Automation

The Java JDK is a package of tools for developing Java-based software, in our case it will be our test automation framework. For this purpose, we will be downloading the Java JDK 11.
NOTE: This is intended for MAC users only
Before downloading,
CHECK IF JDK 11 IS ALREADY INSTALLED ON YOUR DEVICE.
Open your Terminal. Copy and paste the command below then hit return
/usr/libexec/java_home -V
If it returns something like the image below, then Java JDK 11 is already installed on your device. All we need to do is to set up the Java home.

If it’s not yet installed, then let’s proceed.
DOWNLOADING THE JDK 11
Step 1: Go to https://www.oracle.com/ph/java/technologies/javase-jdk11-downloads.html
Step 2: Download the installer suitable for your operating system.

It will ask you to accept Oracle Technology Network License Agreement for Oracle Java SE and to sign in to your Oracle account. If you don’t have an account yet, just create. Then proceed with the download.

Step 3: If you downloaded it on chrome you’ll see the downloaded file on the bottom of your screen. If not, just look for the downloaded file on your downloads folder.

Step 4: Open the downloaded file. A window like the image below will show.

Step 5: Open the .pkg file then proceed with the installation. Just follow the installation instructions.

Step 6: Once installed, verify if it was successfully installed. Follow the steps above on checking if JDK 11 is already installed on your device.
The JAVA_HOME is an environment variable in our operating system that points to the location of our JDK and JRE. Programs or applications that needs java to run or compile java applications will query on the environment variables to look for the JAVA_HOME to get the location of the JDK.
Some automation tools that uses the JAVA_HOME are
- Appium
- Maven
- IntelliJ
If JAVA_HOME is not set properly, you might get the following error when starting the tools mentioned above or when running your automation scripts
- JAVA_HOME environment variable is not set
- JAVA_HOME is set to an invalid directory
- JAVA_HOME is not defined correctly
- JAVA_HOME not found in your environment
So to avoid these, let’s proceed,
SETTING YOUR JAVA_HOME
ASSUMPTION: You are using bash as your terminal shell. If you are using Z shell you can change it to bash. Check this How To Change Default Shell On Mac.
Setting up your JAVA_HOME is simple, just export it on your .bash_profile
STEP 1: Open Finder then go to your Home directory, then look for your .bash_profile

.bash_profile is a hidden file. So if you can’t find it, just run the commands below via Terminal
To show hidden files on Mac
defaults write com.apple.Finder AppleShowAllFiles truekillall Finder
To hide the files
defaults write com.apple.Finder AppleShowAllFiles falsekillall Finder
Step 2: Add the JAVA_HOME on your .bash_profile. Check the first image in this article (List of installed JDK) to know what your Java home is.
export JAVA_HOME=<insert your java home here>
See below for sample

Then that’s it!!!
To sum it up
- Check if JDK 11 is already installed.
- Download the JDK 11 on Oracle website
- Install JDK 11
- Set up JAVA_HOME
Haven’t set up Android Studio yet? Check my other article on How To Download and Set Up Android Studio for Test Automation.