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 one of the previous articles I have written about how to install it on MacOS. In this article I will show you how to install JDK 18 on Windows, add it to the path 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. For the Windows choose (obviously) Windows/x64 zip file. JDK 18 download page

The archive already contains a directory, in this case jdk-18.0.1.1: JDK 18 archive

After the file finished downloading we have to unpack it somewhere. Since I have a few JDKs I keep them all under the same parent directory, in my case c:\Programs\, under which I have subdirectories for JDK11, JDK 17 etc. After unpacking the archive into c:\Programs\, you should see a directory structure similar to this one:

 1c:\Programs\jdk-18.0.1.1>dir
 2 Volume in drive C is OS
 3 Volume Serial Number is B23B-1FAA
 4
 5 Directory of c:\Programs\jdk-18.0.1.1
 6
 705/13/2022  08:03 PM    <DIR>          .
 805/13/2022  08:03 PM    <DIR>          ..
 905/13/2022  08:03 PM    <DIR>          bin
1005/13/2022  08:03 PM    <DIR>          conf
1105/13/2022  08:03 PM    <DIR>          include
1205/13/2022  08:03 PM    <DIR>          jmods
1305/13/2022  08:03 PM    <DIR>          legal
1405/13/2022  08:03 PM    <DIR>          lib
1504/25/2022  08:59 PM             1,243 release
16               1 File(s)          1,243 bytes
17               8 Dir(s)  15,655,849,984 bytes free

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

1c:\Programs\jdk-18.0.1.1>cd bin
2
3c:\Programs\jdk-18.0.1.1\bin>java -version
4openjdk version "18.0.1.1" 2022-04-22
5OpenJDK Runtime Environment (build 18.0.1.1+2-6)
6OpenJDK 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)

We see that the JDK reported version 18 so the installation succeeded!

Setting JAVA_HOME environment variable

Now there is a question whether you should set JAVA_HOME environment variable to point to the JDK 18. Java 18 is not a LTS version so there is a chance you don’t want JAVA_HOME to point to it but rather to the JDK 17 (or even JDK 11). But for completeness, here is the procedure.

Open Control Panel, click User Accounts and then click Change my environment variables on the left. A new window titled Environment Variables will open, like in the image: Environment Variables

Now there are two possibilities: either you already have JAVA_HOME set (like I do) or you don’t. If you have it set, click Edit… and enter c:\Programs\jdk-18.0.1.1 as a value (or the directory where you have unpacked JDK 18). If you don’t have it set, click New… and enter JAVA_HOME for Variable name and c:\Programs\jdk-18.0.1.1 for Variable value (or the directory where you have unpacked JDK 18), like in the image below: Set JDK 18 for JAVA_HOME

Click OK and you should be back to the Environment Variables window. The last step is to add Java to your path.

Adding JDK 18 to PATH

Find variable called Path in the upper pane of the Environment Variables window. Click Edit… and check if you already have a value %JAVA_HOME%\bin. If not, add it and click OK: Add Java to PATH

Click OK until you close all the dialogs and close Control Panel. Now open command prompt and type java -version to see if Java 18 became the default Java version for you. You should see that it is:

1C:\WINDOWS\system32>java -version
2openjdk version "18.0.1.1" 2022-04-22
3OpenJDK Runtime Environment (build 18.0.1.1+2-6)
4OpenJDK 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)

Adding JDK 18 to IntelliJ IDEA

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. adding new SDK in IntelliJ IDEA

Click on the + select Add JDK… and IntelliJ will ask you to select home directory for JDK. Choose the dir into which you have unpacked JDK (e.g. c:\Programs\jdk-18.0.1.1) 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 Windows. Until next time, TheJavaGuy saluts you!