In this article, I’d like to share with you the steps for downloading and installing Java Development Kit (JDK) with OpenJDK 17 on macOS. The same steps may be applied for any Unix operating systems.

You know, OpenJDK is a production-ready, open-source distribution of JDK. And JDK 17 is the latest Long Term Release (LTS) of Java SE platform, as of January 2022.

 

1. Download binary distribution of OpenJDK 17 for macOS

Visit the official download page of OpenJDK 17 at https://jdk.java.net/17, and click on the download link for macOS/x64 if your computer running on Intel’s CPU, or choose macOS/AArch64 for Apple’s CPU:

OpenJDK download page for macOS

It’s strongly recommend to verify SHA256 checksum of the downloaded file against the value published on the website (click the corresponding link sha256). Then open a new terminal window, and type the following command:

      shasum -a 256 openjdk-xxx.tar.gz

Compare the checksum value printed by the shasum command with the value published by the website. If both are identical, you can safely install the archive file.

Then extract the downloaded file .tar.gz to a directory on your computer, either using context menu provided by macOS (right click on the file, Open with > Archive Utility) or using the following command in a terminal session:

                tar -xf openjdk-xxx.tar.gz -C $HOME/OpenJDK

This unzips the archive file to the directory OpenJDK in your user home directory. Explore the extracted directory, and you will see the Java home folder would be $HOME/OpenJDK/jdk-17.0.1.jdk/Contents/Home


2. Install OpenJDK 17 on macOS

Next, you need to set JAVA_HOME and update PATH environment variables so other Java programs and tools could find JDK. In the terminal, type the following command to create the Z-Shell resource file:

cat > .zshrc

export JAVA_HOME=$HOME/jdk-17.0.1.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH

Press Control + D to save the file. The .zshrc file is run whenever a new terminal session is initialized, which sets JAVA_HOME and update PATH environment variables.

NOTE: If you’re using Bash shell, create the .bash_profile file instead of .zshrc file.

Quit the terminal and start a new session. Then type java -version command, you should see the following output:

java version on macOS

That means you have successfully installed OpenJDK on your Mac. To see the steps in action, watch the following video:

 

Related Articles:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.

Add comment

   


Comments 

#1HG Yang2023-03-12 08:46
Thanks very much, it os a Nice Help :-)
Quote