How to install OpenJDK on Windows
Download
Start by navigating to the https://jdk.java.net/ and download the latest build. At the time of writing, JDK23 is the latest version and can be found at https://jdk.java.net/23/.
Download the zip file shown next to Windows/x64. Although you could unzip the contents anywhere on your computer, I recommend that you should place them in C:\Program Files\OpenJDK
, inside a folder named the same way the current JDK version is. Since I am downloading JDK23, I will unzip the contents of the zip file into C:\Program Files\OpenJDK\23\
.
Environment Variables
With the correct files downloaded, we now need to set up environment variables for our installation. Open the control panel and navigate to: Windows Settings -> System -> About -> Advanced system settings (upper right) -> Advanced -> Environment Variables
. On this window you will see two areas: the upper one is variables associated with your Windows account and the bottom is variables associated with the system (all accounts on your system). Depending on who you would like to access your OpenJDK installation, you would either edit variables for just your user or the whole system. I recommend editing the System variables.
First we need to create JAVA_HOME
, do this by clicking New, entering the variable name JAVA_HOME
and set the value to where you unzipped the OpenJDK download, for example C:\Program Files\OpenJDK\23
, and then click OK.
We also need to add the bin
folder of our installation to our Path
so that we can execute java by writing java
in our command line. Since the environment variable Path
already exists, for both our user and the system, we need to edit that variable. Find it in the list of variables and click Edit
, then click New, which creates a new line where you should enter %JAVA_HOME%\bin
. This will make all the executable files inside %JAVA_HOME%\bin
executable in our terminal by simply writing their name. You can verify this by running java --version
in a terminal.
Note: If you update your OpenJDK installation in the future, say by downloading JDK24 and placing it in C:\Program Files\OpenJDK\24
, you only have to change the JAVA_HOME
environment variable to point to that location instead of the old one. You do not have to change the line we added in Path
since that is dependent on the JAVA_HOME
environment variable.
Associate File Type(s)
Start by opening cmd as administrator by searching for “cmd” in Windows and clicking Run as administrator
.
In the administrator cmd, type the following, which associates the .jar
extension with the jarfile
name, and then sets the executable program for jarfile
to our installation of OpenJDK (mapped to javaw.exe
which is a non-console version of the application launcher, usually used for GUI applications).
assoc .jar=jarfile
ftype jarfile="%JAVA_HOME%\bin\javaw.exe" -jar "%1" %*
Troubleshooting File Type Association
If for some reason the previous instruction does not work it might be because of an earlier installation of java breaking the associated types. Try one of the following steps:
-
Open the Registry Editor, done for example by pressing
Win + R
, typingregedit
and clicking Enter. Search for:Computer\HKEY_CLASSES_ROOT\.jar
and double-click the first line to the right named(Default)
and set theValue data:
tojarfile
. -
If all else fails, try opening the registry editor, like mentioned in the step above, and searching for
Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jar
and right-click the.jar
folder to the left and click Delete. Now go to #Associate File Type(s) and associate the file types again.