Install the Latest Oracle JDK on Mac

This article shows you how to install Oracle JDK $java_version on your Mac system. This article uses JDK $java_version$java_update_no to demonstrate the installation. In the provided commands, replace the version specific paths and file names according to the downloaded version.

Oracle provides a Mac installer and a binary file.This article explains how to install Oracle JDK using the mac installer and how to set the JAVA_HOME variable.

Install Oracle JDK $java_version on Linux

Step 1:
Download the macOS installer(jdk-$java_version$java_update_no_osx-x64_bin.dmg) from this official site:

Step 2:
Double-click the jdk-$java_version$java_update_no_osx-x64_bin.dmg file. You will see a finder window with the JDK $java_version$java_update_no.pkg file. Double-click the JDK $java_version$java_update_no.pkg file to start the installer.

Step 3:
Click "Continue" and follow the installation wizard to install Oracle JDK.
Step 4:
After installing Java, close the installation wizard, open the terminal and enter the following two commands to check the installed java and javac version.
java -version
javac -version

If you see the installed Java version for both of these commands, you have successfully installed the Oracle JDK.

Step 5:
Some software like Apache Maven requires the JAVA_HOME path to find the active Java path. Based on the Terminal Shell, the JAVA_HOME path must be declared either in the ~/.bash_profile or the ~/.zshenv file.

Step 5.1:
Enter the following command to get the installed Java locations. If you have more than one Java installations, you will see all of them listed in the output.

You may get an output similar to this:

In case if you have multiple Java installations, all their installation folders will be listed here. Pick the one you want to set as the default Java Home.

Step 5.2:
Enter the following command to check the Shell type.
echo $SHELL
If you are running macOS Catalina or latest, you will get /bin/zsh as the shell type. Older Mac versions use /bin/bash as the default shell.

Step 5.3:
If the default shell is "bash", enter the following command to edit the ".bash_profile" file.
nano ~/.bash_profile

If the default shell is "zsh", use the following command to edit the ".zshenv" file.
nano ~/.zshenv

nano is used here to open the profile file. You can use your favorite editor instead of nano.

Step 5.4:
In the opened file, add the following line to define JAVA_HOME.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-$java_version$java_update_no.jdk/Contents/Home
Save the changes and close nano (Ctrl + O, Ctrl + X).

Step 6:
Enter the following commands to test if the JAVA_HOME is properly set.
Run the following command if your shell is bash:
source ~/.bash_profile
Run the following command if your shell is zsh:
source ~/.zshenv
If you see the path you set in the profile file, congratulations! You have successfully installed the latest Oracle JDK on your Mac.

Step 9:
Restart the computer to avoid running source command every time you open the terminal.
Next Post »


Write comments
Abid Ovi
July 16, 2021 at 5:04 PM delete

great article thhanks for share thisnews


Contact Form


Email *

Message *