To run and develop any Java applications, a Java Development Kit (JDK) is required. In this post, I’d like to share with you how to setup OpenJDK - a production-ready and open-source distribution of JDK.

And you know, JDK 20 is just a regular update (non LTS - Long Term Support) release of Java SE platform. It was released on March 21st 2023.

 

1. Download binary distribution of OpenJDK 20 for macOS

OpenJDK 20 is distributed as archive (tar.gz) file for macOS. No installer. Visit the OpenJDK 20’s official download page. The following screen will appear:

openjdk 20 download page macos

There are two different download links for macOS, and which one you should choose depending the CPU type of your Mac computer. The download link tar.gz next to macOS/AArch64 is for Mac running on Apple CPU, whereas the link for macOS/x64 is for Mac running on Intel CPU.

For example, if your Mac running on Apple M1 chip so you should click the link 1 (tar.gz) to download the binary distribution of OpenJDK 20 for macOS. You’ll get the file openjdk-20.0.1_macos-aarch64_bin.tar.gz downloaded onto your computer.

And it’s strongly recommended to verify integrity of the downloaded file to ensure that it was not tampered with during the download. Open a new Terminal window, change the current directory to location of the file, then type the following command:

shasum -a 256 openjdk-20.0.1_macos-aarch64_bin.tar.gz

Then compare the generated checksum value against the one published on the download page (click link 2). If both are the same, that means you can safely use the archive file.


2. Install OpenJDK 20 on macOS



Next, extract the archive file to a desired location on your computer. For example, use the following command:

tar -xf openjdk-20.0.1_macos-aarch64_bin.tar.gz -C $HOME/OpenJDK

This will extract the compressed archive file into the directory OpenJDK in the user home directory. Then the JDK home directory will be OpenJDK/jdk-20.0.1.jdk/Contents/Home (you can verify by some ls commands)  under your user home directory.

Then you need to set 2 environment variables JAVA_HOME and PATH by updating the Shell resource file. If the current shell is Z-Shell, use the following commands that appends 2 lines to the .zshrc file (the current directory must be user home):

cat >> .zshrc

export JAVA_HOME=$HOME/OpenJDK/jdk-20.0.1.jdk/Contents/Home

export PATH=$JAVA_HOME/bin:$PATH

The first export command sets the environment variable JAVA_HOME to JDK home directory. And the second one updates the environment variable PATH so all files under JDK home’s bin directory can be found.
NOTE: If the current shell is Bash, you should update the .bash_profile file under your user home directory.

Now, quit the Terminal completely and open it again. Then type java -version and javac -version to verify the installation. You will see the following output:

open jdk 20 version on macos

Congratulations! You have installed OpenJDK 20 successfully on macOS, so you now can start running and developing Java applications. Watch the following video to see the steps in action:

 

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 

#1Duc Pham2023-05-18 04:47
Thanks for sharing Thanks for sharing Thanks for sharing Thanks for sharing
Quote