Java 19 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 19 on MacOS and to setup IntelliJ IDEA so you can write Java applications against it.

First you have to visit https://jdk.java.net/19/. 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. JDK 19 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 JDK .tar.gz file and typing tar -zxf openjdk-19_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-18.jdk
 5│   └── Contents
 6│       ├── Home
 7│       │   ├── bin
 8│       │   ├── conf
 9│       │   ├── include
10│       │   ├── jmods
11│       │   ├── legal
12│       │   └── lib
13│       ├── MacOS
14│       └── _CodeSignature
15├── jdk-19.jdk
16│   └── Contents
17│       ├── Home
18│       │   ├── bin
19│       │   ├── conf
20│       │   ├── include
21│       │   ├── jmods
22│       │   ├── legal
23│       │   └── lib
24│       ├── MacOS
25│       └── _CodeSignature
26...
27
2858 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-19.jdk/Contents/Home/bin
3
4# ivanmilosavljevic @ ARTEMIS in ~/jdk/jdk-19.jdk/Contents/Home/bin [13:54:07]
5$ ./java -version
6openjdk version "19" 2022-09-20
7OpenJDK Runtime Environment (build 19+36-2238)
8OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)

We see that the JDK reported version 19 (build 19+36-2238) so the installation succeeded! If you have multiple projects that use different versions of Java, the easiest way to manage them is to use excellent jEnv. I have an entire article explaining how senior developers manage multiple JDKs with jEnv.

Now let’s see how you can 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. adding new SDK in IntelliJ IDEA

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

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