Blog

How to install Java 18 (OpenJDK 18) on MacOS

The easiest way to install Java 18 (OpenJDK 18) on MacOS

Java 18 is currently the latest version of Java. Even though it isn’t an LTS release, it’s worth installing it so we can test new features. In this article I will show you how to install JDK 18 on MacOS and to set up IntelliJ IDEA so you can write Java applications against it.

First, you have to visit https://jdk.java.net/18/. Near the top you’ll see the build number and download links for various operating systems. If you have a new M1 Mac, choose macOS/AArch64; otherwise, choose macOS/x64. After the file finished downloading, we have to unpack it because it’s a gzipped tar file. JDK 18 download page

Since I have a few JDKs, I keep them all under the same parent directory, in my case ~/jdk. Unpack JDK by opening your terminal (such as iTerm2, kitty, Terminal…), going to the directory in which you saved the JDK .tar.gz file, and typing tar -zxf openjdk-18-ea+28_macos-x64_bin.tar.gz -C ~/jdk. After doing this, if you go to the dir where you unpacked JDK (again, in my case it’s ~/jdk), you should see a directory structure very similar to this one:

# ivanmilosavljevic @ TJG in ~/jdk [13:53:18]
$ tree -d -L 4
.
├── jdk-17.0.1.jdk
│   └── Contents
│       ├── Home
│       │   ├── bin
│       │   ├── conf
│       │   ├── include
│       │   ├── jmods
│       │   ├── legal
│       │   └── lib
│       ├── MacOS
│       └── _CodeSignature
└── jdk-18.jdk
   └── Contents
       ├── Home
       │   ├── bin
       │   ├── conf
       │   ├── include
       │   ├── jmods
       │   ├── legal
       │   └── lib
       ├── MacOS
       └── _CodeSignature

22 directories

The most important files are in the bin directory, so let’s verify that the proper version is installed there:

# ivanmilosavljevic @ TJG in ~/jdk [13:54:02]
$ cd jdk-18.jdk/Contents/Home/bin

# ivanmilosavljevic @ TJG in ~/jdk/jdk-18.jdk/Contents/Home/bin [13:54:07]
$ ./java -version
openjdk version "18-ea" 2022-03-22
OpenJDK Runtime Environment (build 18-ea+28-1975)
OpenJDK 64-Bit Server VM (build 18-ea+28-1975, mixed mode, sharing)

We can see that the JDK reported version 18-ea build 28, so the installation succeeded! Now let’s look at how to use this JDK from IntelliJ IDEA.

In IntelliJ, open any Java project (or create a new one) and go to File/Project Structure. In the Project Structure window, choose Platform Settings/SDKs and click on the + sign at the top. adding new SDK in IntelliJ IDEA

Choose Add JDK… and IntelliJ will ask you where your JDK is. Choose the path ~/jdk/jdk-18.jdk/Contents/Home and you should see JDK 18 added to your IntelliJ. Click OK and it’s done! You’ve successfully added JDK 18 to IntelliJ IDEA. JDK 18 added to IntelliJ IDEA

Dear fellow developer, thank you for reading this article about installing JDK 18 on MacOS. Until next time, TheJavaGuy salutes you 👋!

You like this post? Share it with your friends on:

© 2022-2026 Ivan Milosavljević (TheJavaGuy)

Built with Astro using modified Astrofy template