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.
The archive already contains a directory, in this case
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-220.127.116.11>dir 2 Volume in drive C is OS 3 Volume Serial Number is B23B-1FAA 4 5 Directory of c:\Programs\jdk-18.104.22.168 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-22.214.171.124>cd bin 2 3c:\Programs\jdk-126.96.36.199\bin>java -version 4openjdk version "188.8.131.52" 2022-04-22 5OpenJDK Runtime Environment (build 184.108.40.206+2-6) 6OpenJDK 64-Bit Server VM (build 220.127.116.11+2-6, mixed mode, sharing)
We see that the JDK reported version 18 so the installation succeeded!
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:
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.104.22.168 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-22.214.171.124 for Variable value (or the directory where you have unpacked JDK 18), like in the image below:
Click OK and you should be back to the Environment Variables window. The last step is to add Java to your 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:
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 "126.96.36.199" 2022-04-22 3OpenJDK Runtime Environment (build 188.8.131.52+2-6) 4OpenJDK 64-Bit Server VM (build 184.108.40.206+2-6, mixed mode, sharing)
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.
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-220.127.116.11) 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 Windows. Until next time, TheJavaGuy saluts you!