Java 18 is currently the latest version of Java. Even though it isn’t a 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 setup 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 build number and download links for various operating systems. If you have new M1 Mac choose macOS/AArch64, otherwise choose macOS/x64. After the file finished downloading we have to unpack it because it’s gzipped tar file.
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 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:
1# ivanmilosavljevic @ TJG in ~/jdk [13:53:18]
2$ tree -d -L 4
3.
4βββ jdk-17.0.1.jdk
5βΒ Β βββ Contents
6βΒ Β βββ Home
7βΒ Β βΒ Β βββ bin
8βΒ Β βΒ Β βββ conf
9βΒ Β βΒ Β βββ include
10βΒ Β βΒ Β βββ jmods
11βΒ Β βΒ Β βββ legal
12βΒ Β βΒ Β βββ lib
13βΒ Β βββ MacOS
14βΒ Β βββ _CodeSignature
15βββ jdk-18.jdk
16 βββ Contents
17 βββ Home
18 βΒ Β βββ bin
19 βΒ Β βββ conf
20 βΒ Β βββ include
21 βΒ Β βββ jmods
22 βΒ Β βββ legal
23 βΒ Β βββ lib
24 βββ MacOS
25 βββ _CodeSignature
26
2722 directories
The most important files are in the bin
directory, so let’s verify that the proper version is installed there:
1# ivanmilosavljevic @ TJG in ~/jdk [13:54:02]
2$ cd jdk-18.jdk/Contents/Home/bin
3
4# ivanmilosavljevic @ TJG in ~/jdk/jdk-18.jdk/Contents/Home/bin [13:54:07]
5$ ./java -version
6openjdk version "18-ea" 2022-03-22
7OpenJDK Runtime Environment (build 18-ea+28-1975)
8OpenJDK 64-Bit Server VM (build 18-ea+28-1975, mixed mode, sharing)
Tip
You can always open Project Structure by pressing β+;
We see that the JDK reported version 18-ea build 28 so the installation succeeded! Now let’s see how to use this JDK from the IntelliJ IDEA.
Note
Minimal version of IntelliJ that supports Java 18 is 2022.1! If you use some earlier one you will be able to add JDK 18 but not to use any of the new features.
In IntelliJ, open any Java project (or create a new one) and go to File/Project Structure. In a Project Structure window choose Platform Settings/SDKs and click on a + sign on the top.
Tip
You can always open Project Structure by pressing β+;
Choose Add JDK⦠and IntelliJ will ask you where your JDK is. Choose 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 the IntelliJ IDEA.
Dear fellow developer, thank you for reading this article about installing JDK 18 on MacOS. Until next time, TheJavaGuy saluts you!
Comments