OpenJDK is a production-ready, open-source distribution of Java SE Development Kit (JDK). And JDK 18 is a regular update (non-LTS) of Java SE.

Below, you’ll find the guide about downloading and installing OpenJDK 18 on macOS operating system. The similar steps can be applied for any Linux operating systems.

 

1. Download binary distribution of OpenJDK 18 for macOS

Head over to OpenJDK 18’s official download page, you will see some download links of archive files (tar.gz) as follows:

openjdk 18 download page macos

Click the link tar.gz next to macOS/AArch64 if your Mac computer running on Apple’s CPU. Or click the macOS/x64 tar.gz link for Intel’s CPU.

It’s strongly recommend to verify SHA256 checksum of the downloaded archive 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-18.0.1_macos-aarch64_bin.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 OpenJDK 18.



Then extract the downloaded archive file 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 -xfopenjdk-18.0.1_macos-aarch64_bin.tar.gz -C $HOME/OpenJDK

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

 

2. Install OpenJDK 18 on macOS

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

cat > .zshrc

export JAVA_HOME=$HOME/OpenJDK/jdk-18.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 and javac -version, you should see the following output:

check openjdk 18 version on macos

That means you have successfully installed OpenJDK 18 on macOS. 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 

#3Edb2023-03-30 07:01
Should mention that cat > .zshrc will overwrite the content of the file, if it exists. Learned that the hard way...
Quote
#2nal2023-01-24 09:49
Hi, question, I followed everything in the video, however when I type java -version or javac -version in terminal I keep getting the following: javac 11.0.17 or java version "11.0.17" 2022-10-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.17+10-LTS-269)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.17+10-LTS-269, mixed mode) please advise!
Quote
#1Tom2022-11-13 14:00
Thank you! I'm new with Mac and your video helped a lot!
Quote