In this article, I’d like to share the steps to setup Java runtime on macOS operating system, with the open-source Java Development Kit (OpenJDK) version 19.

You know, OpenJDK 19 is a free, open-source distribution of JDK, which was released on September 20th 2022. It’s a regular feature release - not Long Term Support (LTS) one.

 

1. Download binary distribution of OpenJDK 19 for macOS

OpenJDK is distributed in form of compressed archive file (tar.gz for Linux/macOS). Head over to OpenJDK 19 official download page, you will see the following page:

open jdk 19 download page macos

If you Mac running on Apple chip, click the link tar.gz next to macOS/AArch64 (link number 1in the screenshot above). Otherwise click the link tar.gz next to macOS/x64 if your Mac running on Intel CPU. It will download the archive file openjdk-19.0.1_macos-aarch64_bin.tar.gz onto your computer.

And you should check the integrity of the downloaded file by comparing its SHA256 checksum against the value published (link number 2). So open a new Terminal window, change the current directory to location of the archive file, and type the following command:

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

If the SHA256 checksum printed by this command is equal to the one published on the download page, you can safely proceed next.


2. Install OpenJDK 19 on macOS

Next, you need to extract the archive file to a specific location, e.g. OpenJDK in your user home. In Terminal, you can type the following command:

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



This extracts the archive file into OpenJDK directory in your user home directory. Do some ls commands you will see the JDK home directory is at OpenJDK/jdk-18.0.1.jdk/Contents/Home.

Next, you need to set/update 2 system environment variables JAVA_HOME and PATH. On my Mac, Z-Shell is the default shell for Terminal, so I need to use the following command to update the Z-Shell resource file:

cat >> .zshrc

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

export PATH=$JAVA_HOME/bin:$PATH

Enter a new line and press Ctrl + D to save the file. If you’re using Bash shell, update the .bash_profile file instead.

Finally, to verify if OpenJDK installed properly or not, terminate the current Terminal window completely. Open a new one and type java -version and javac -version commands. You should see the following output:

check open jdk 19 on macOS

That means OpenJDK 19 has been installed successfully on macOS. I recommend you watch the following video to see the steps in action:

 

Related Articles:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment