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:
1ivanmilosavljevic @ ARTEMIS 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 @ ARTEMIS in ~/jdk [13:54:05] 2$ cd jdk-18.jdk/Contents/Home/bin 3 4# ivanmilosavljevic @ ARTEMIS 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)
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 IntelliJ IDEA.
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.
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 IntelliJ IDEA.
Dear fellow developer, thank you for reading this article about installing JDK 18 on MacOS. Until next time, TheJavaGuy saluts you!