Download and Install OpenJDK 20 on macOS
- Details
- Written by Nam Ha Minh
- Last Updated on 31 December 2023   |   Print Email
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:
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
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:

Related Articles:
- How to set JAVA_HOME in macOS and Linux permanently
- How to set JAVA_HOME environment variable on Windows 10
- What are JVM, JRE and JDK
- How to write, compile and run a hello world Java program for beginners
- Java Core Language Tutorials
About the Author:

Comments