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: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
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: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:
- 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
Comments