How to install openjdk on windows

This tutorial provides all the steps required to install OpenJDK 17 on Windows 10. The steps to install OpenJDK 17 on other versions of Windows should be similar to the steps explained in this tutorial.

You may also install the popular IDEs to develop Java applications by following — How To Install Eclipse For Java On Windows, How To Install IntelliJ IDEA for Java on Windows, and How To Install VSCode For Java On Windows. You may also follow the How To Install OpenJDK 17 On Ubuntu to install the latest OpenJDK on Ubuntu and How To Install Java 17 On Ubuntu to install Oracle JDK.

Notes: New version of this tutorial is available at How To Install OpenJDK 18 On Windows.

Step 1 — Download OpenJDK

Open the JDK 17 GA Release site and download the distribution for Windows as highlighted in Fig 1.

Install Java 17 or OpenJDK 17 on Windows 10 - Download Options

Fig 1

Click the zip download link as highlighted in Fig 1 to download OpenJDK for Windows. Also, verify your download using the given sha256 checksum.

Step 2 — Install OpenJDK

Extract the downloaded zip to the desired location. In my case, I have extracted the downloaded zip to C:\java\openjdk. The final path should be C:\java\openjdk\jdk-17.

This is the only step required to install OpenJDK on windows.

Step 3 — Set Environment Variables

In this step, we will configure the environment variables to use the OpenJDK from Command Prompt. Open Command Prompt and check the installed version of Java using the command java -version as shown in Fig 2.

Install Java 17 or OpenJDK 17 on Windows 10 - Verify Installation

Fig 2

It shows the version of Java 17 since my current version of Java is 17. In your case it might show another version of Java if it’s already installed, else it will show the message — Java is not recognized as internal or external command, operable program or batch file.

Right Click -> My Computer(This PC) -> Properties -> Advanced System Settings

The above steps will open the Windows Settings Panel as shown in Fig 3.

Install Java 17 or OpenJDK 17 on Windows 10 - Advanced Options

Fig 3

Now click the Environment Variables Button, select Path under the System Variables section, and click the Edit Button. We need to add the path of the installed JDK to the system Path.

Click on the New/Edit Button and add/update the path to the installed JDK bin which is C:\java\openjdk\jdk-17\bin in our case. You might be required to update the path if it already exists. It should look like Fig 4.

Install Java 17 or OpenJDK 17 on Windows 10 - Configure Path

Fig 4

Press the OK Button 3 times to close all the windows. This sets the JDK 17 on system environment variables to access the same from the console.

Notes: Remove existing PATH values specific to previously installed Java. Also update JAVA_HOME, in case it was already set. Also, you might be required to remove the previously installed JDK from the Global Path as shown in Fig 5.

Install Java 17 or OpenJDK 17 on Windows 10 - Remove Global Path

Fig 5

Now again open the console and test the Java version as shown in Fig 6. Make sure to use a new console to test the version of the newly installed OpenJDK 17.

Install Java 17 or OpenJDK 17 on Windows 10 - Verify Installation

Fig 6

It must show the OpenJDK version as shown in Fig 6. You might need to restart the system in case it does not reflect the JDK version installed by us.

Getting started with Java — Hello World

In this step, we will write, compile, and execute our first program in Java using the standard Hello World example.

Now write the first Java program as shown below, save the program as HelloWorld.java and exit the editor. Make sure that the class name and file name are the same.

class HelloWorld {

public static void main( String[] args ) {

System.out.println( "Hello World !!\n" );
}
}

Now open the command prompt and navigate to the path where you have saved your Java program. Use the below-mentioned commands to compile and execute the program.

# Compile - Specify file name and extension
javac HelloWorld.java

# Execute - Spicy file name
java HelloWorld

# Output
Hello World !!

These are the easy-to-install steps required to install OpenJDK on Windows and write and execute the Java program.

Summary

This tutorial provided the steps required to download and install the most recent versions of OpenJDK i.e. JDK 17 and also provided the steps to write, compile, and execute the first Java program.

Details
Written by  
Last Updated on 04 May 2023   |   Print  Email

This post will guide you how to setup Java Development Kit version 20 on Windows operating system, with OpenJDK distribution. JDK 20 is a just regular update of Java SE platform, with most new features are still in incubator or preview stage.

And you know, OpenJDK 20 is a production-ready and open-source build of the JDK 20, which was released on March 21st 2023. To install OpenJDK 20 on Windows, kindly follow the steps described below.

 

1. Download binary distribution of OpenJDK 20

OpenJDK 20 is distributed as compressed archive files (zip and tar.gz) — no installer or setup program. Head over to JDK 20’s official download page, you will see the following page:

OpenJDK 20 download page

For Windows OS, click the hyperlink “zip” next to Windows/x64 as shown in the above screenshot. The result is the zip file openjdk-20.0.1_windows-x64_bin.zip being downloaded on your computer (around 187 MB in file size).

Next, you should verify the downloaded by checking SHA256 checksum value. Open a new Command Prompt on Windows, change the current directory to where the file is downloaded, and type the following command:

certutil -hashfile openjdk-20.0.1_windows-x64_bin.zip sha256

Then compare the SHA256 checksum value printed by this command against the value published on the official download page (link “sha256” as pointed in the above screenshot). And you can safely process if two values are the same.

 

Next, unzip the downloaded archive file. You can use the following command:

tar -xf openjdk-20.0.1_windows-x64_bin.zip

The result is a new directory created with the name jdk-20.0.1 — that contains the binary files of OpenJDK 20.

Then you need to set the system environment variables JAVA_HOME and PATH in the following form:

       JAVA_HOME = [Path to OpenJDK directory]

       PATH = JAVA_HOME\bin + PATH

For detailed instruction about setting up JAVA_HOME environment variable, check this article.

Finally, open a new command prompt window and type java -version to verify the installation. You should see the following output:

java version 20

You see, it prints openjdk version “20.0.1” — that means you have installed OpenJDK 20 on Windows successfully. You can also type javac -version to check version of Java compiler. You can also watch the following video to see the steps in action:

 

Learn more:

  • How to check Java version
  • Java SE versions history
  • How to set JAVA_HOME environment variable on Windows 10
  • How to set environment variables for Java using command line
  • How to write, compile and run a hello world Java program for beginners
  • What are JVM, JRE and JDK

About the Author:

Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.

Add comment

In the past, Oracle used to publish an executable installers for Windows that would:

  • Unpack files
  • Add registry keys indicating the installed version and path
  • Add the JRE to the system PATH
  • Register an uninstaller with Windows.

As of Java 11, the Oracle’s free version of Java (Oracle OpenJDK) doesn’t seem to include an installer. It is just a zip file containing the binaries.

How are we supposed to install OpenJDK 11 on Windows seeing as the aforementioned integrations are no longer there? Aren’t they necessary?

asked Sep 26, 2018 at 7:01

Gili's user avatar

GiliGili

86.5k97 gold badges392 silver badges692 bronze badges

17

  1. Extract the zip file into a folder, e.g. C:\Program Files\Java\ and it will create a jdk-11 folder (where the bin folder is a direct sub-folder). You may need Administrator privileges to extract the zip file to this location.

  2. Set a PATH:

    • Select Control Panel and then System.
    • Click Advanced and then Environment Variables.
    • Add the location of the bin folder of the JDK installation to the PATH variable in System Variables.
    • The following is a typical value for the PATH variable: C:\WINDOWS\system32;C:\WINDOWS;"C:\Program Files\Java\jdk-11\bin"
  3. Set JAVA_HOME:

    • Under System Variables, click New.
    • Enter the variable name as JAVA_HOME.
    • Enter the variable value as the installation path of the JDK (without the bin sub-folder).
    • Click OK.
    • Click Apply Changes.
  4. Configure the JDK in your IDE (e.g. IntelliJ or Eclipse).

You are set.

To see if it worked, open up the Command Prompt and type java -version and see if it prints your newly installed JDK.

If you want to uninstall — just undo the above steps.

Note: You can also point JAVA_HOME to the folder of your JDK installations and then set the PATH variable to %JAVA_HOME%\bin. So when you want to change the JDK you change only the JAVA_HOME variable and leave PATH as it is.

Georg Schölly's user avatar

Georg Schölly

124k49 gold badges221 silver badges267 bronze badges

answered Sep 27, 2018 at 6:51

Lior Bar-On's user avatar

Lior Bar-OnLior Bar-On

10.8k5 gold badges34 silver badges46 bronze badges

17

Java 17 (LTS) and up

For Java 17 and up, you can use the Eclipse Adoptium website. According to their about section, the Eclipse Adoptium project is the continuation of the original AdoptOpenJDK mission.

Java 11 (LTS), Java 8 — 16

For Java 11 (8 through 16), you can use AdoptOpenJDK, a website hosted by the java community. You can find .msi installers for OpenJDK 8 through 16 there, which will perform all the things listed in the question (Unpacking, registry keys, PATH variable updating (and JAVA_HOME), uninstaller…).

answered May 27, 2019 at 13:47

Pimgd's user avatar

PimgdPimgd

5,9831 gold badge30 silver badges45 bronze badges

2

Use the Chocolatey packet manager. It’s a command-line tool similar to npm. Once you have installed it, use

choco install openjdk --version=11.0

in an elevated command prompt to install OpenJDK 11 (leave out the --version parameter to install the latest version).

To update an installed version to the latest version, type

choco upgrade openjdk

Pretty simple to use and especially helpful to upgrade to the latest version. No manual fiddling with path environment variables.

answered Jun 18, 2019 at 12:34

Tobias's user avatar

TobiasTobias

2,0892 gold badges26 silver badges51 bronze badges

11

From the comment by @ZhekaKozlov: ojdkbuild has OpenJDK builds (currently 8 and 11) for Windows (zip and msi).

4

You can use Amazon Corretto. It is free to use multiplatform, production-ready distribution of the OpenJDK. It comes with long-term support that will include performance enhancements and security fixes. Check the installation instructions here.

You can also check Zulu from Azul.

One more thing I like to highlight here is both Amazon Corretto and Zulu are TCK Compliant. You can see the OpenJDK builds comparison here and here.

answered Apr 27, 2020 at 17:39

Swapnil's user avatar

SwapnilSwapnil

1,0341 gold badge13 silver badges21 bronze badges

In addition to the above answers, it is worth noting that you have to move your JDK Path entry to the top of the Path

Inside System Variables Edit Path and Move Up the latest JDK entry to the top

answered May 12, 2022 at 17:10

Prince's user avatar

PrincePrince

20.4k6 gold badges39 silver badges59 bronze badges

Scoop installs programs you know and love, from the command line with a minimal amount of friction.

  • Install scoop
  • Add java scoop bucket add java
  • Install OpenJDK scoop.cmd install openjdk17

answered Jan 2 at 14:06

jfk's user avatar

jfkjfk

4,41534 silver badges30 bronze badges

https://www.openlogic.com/openjdk-downloads allowed me to pick a 32-bit version of OpenJDK8 (don’t ask — Arduino IDE doesn’t compile with 11), I think they just wrap around AdoptOpenJDK MSIs but I couldn’t find 32-bit distros on AdoptOpenJDK.

answered Mar 26, 2021 at 19:06

David Airapetyan's user avatar

David AirapetyanDavid Airapetyan

5,3314 gold badges40 silver badges62 bronze badges

WinGet is now available on Windows 10+ to install the Microsoft Build of OpenJDK on your machine. See details and access the downloads page at https://aka.ms/msopenjdk/ where you can find more instructions and packages you may find useful.

answered Sep 29, 2022 at 6:17

d3r3kk's user avatar

d3r3kkd3r3kk

3,5553 gold badges18 silver badges22 bronze badges

Here is the complete answer. first of all you have to install the Chocolatey. to install Chocolatey run powershell as administrator and run the following command

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

after this run open cmd as administrator and run this command

choco install -y openjdk11

it will install the openjdk to the following location

C:\Program Files\Eclipse Adoptium\jdk-11.0.16.101-hotspot

finllay set your JAVA_HOME TO

C:\Program Files\Eclipse Adoptium\jdk-11.0.16.101-hotspot

and cheers

answered Sep 28, 2022 at 12:44

Engr.Aftab Ufaq's user avatar

Engr.Aftab UfaqEngr.Aftab Ufaq

3,6494 gold badges22 silver badges53 bronze badges

Try this also.
choco install -y microsoft-openjdk11

answered Jun 6 at 13:19

Nabeel Ali's user avatar

How to Install OpenJDK (Free Java) – Multi OS Guide

In a nutshell, there are two coexisting branches of Java: the proprietary, closed-source Oracle Java and the community-maintained open-source OpenJDK.

OpenJDK is licensed under GPL-2.0, and it consists of a Java Virtual Machine and a java-bytecode compiler. Since this is the easier and cheaper way, it’s the one we’re going to be using in this tutorial.

Here, you’ll learn how to install OpenJDK on Windows, Mac, and Linux in a few different ways.

Very Easy Semi-Automatic Mode – for Windows and macOS

Keep in mind that this will require administrator access.

If you are in a hurry and just want a plug-and-play install with an easy uninstaller and automatic setup, that’s fine – I won’t judge. :)

Head over to the community-driven, Eclipse Foundation-supported Adopt Open JDK website to get the link for your installer (if you are in doubt, just go with OpenJDK 11 LTS on HotSpot JVM).

Also, Eclipse is the main open-source Java IDE in case you didn’t know.

You’ll be redirected to a page with a list of install links. Look for your OS, choose the packaged installer (.msi for Windows or .pkg for macOS) and download it. Remember to install ALL features, as it won’t work out of the box if you don’t allow the installer to set JAVA_HOME. Then run it and voilà! You’re done.

Very Easy Semi-Automatic Mode – for Linux

This method also needs admin access, of course.

First, remember to run this command:

sudo apt-get update

Your OS will very likely have its own OpenJDK package available in the repository manager.

For Ubuntu/Debian, the package names are usually named like openjdk-<version_number>-jre-headless. For example:

sudo apt install openjdk-8-jre-headless # installs for java 8
or
sudo apt install openjdk-13-jre-headless # installs for java 13

That’s it, the open-source community saves the day again.

Still Pretty Easy, Mostly Manual Mode – for Windows, macOS, and Linux

You can get your compressed OpenJDK from a number of different vendors such as Microsoft, Red Hat, Intel or anyone offering their fork of OpenJDK. They might even offer their own installer file. But to keep it simple we’re using Adopt Open JDK once again.

Select your preferred version and JVM ( OpenJDK 11 LTS on HotSpot JVM if you are unsure) and download the compressed JDK.

Why would you choose this option over the much easier methods just described above? Maybe you don’t have administrator rights on your current machine or maybe you are setting up your own strategy to manage multiple Java versions. I don’t know, but it has its use cases.

Steps for Windows

  1. Store the extracted files in the Directory Tree

First, extract the zip file into a folder (C:\Program Files\OpenJDK would be the educated choice. Note that \OpenJDK was manually added). It will create the folder for the JDK installation, with \bin as one of its sub-directories.

You will need Administrator privileges to extract the zip file to this location.

If you cannot use Administrator rights for any reason, extract it to a location under your user space, such as C:\Users\%YOUR_USERNAME%\OpenJDK.

2.  Open Environment Variables

Open the Control Panel > System & Security > System > Advanced System Settings (it’ll be under ‘Device Specifications in Windows 10+).

In the System Properties window, select the Advanced tab, then Environment Variables.

3.   Set JAVA_HOME:

Under System Variables, click New. Enter the variable name as JAVA_HOME. Enter the variable value as the installation path of the JDK (appending the \bin sub-folder at the end of the path). Mine was C:\Program Files\OpenJDK\OpenJDK11U-jdk_x64_windows_hotspot_11.0.15_10\jdk-11.0.15+10\bin.

Click OK and Apply Changes. If you are doing this process as a non-admin, choose User Variables instead.

4.   Add the binary executables to PATH:

Stay in the Environment Variables window. Click on the variable named Path (either for System or User, depending on your choice in the last section).

You’ll see a list of stuff. These are the executables you have access from your CLI (like Windows Terminal, Command Prompt, or Poweshell).

Click on ‘New’ at the top-right corner and add %JAVA_HOME% as a variable.

Click OK and Apply Changes.

5.   Test Installation

Open a Command Line Interface. Type java -version. If the output was the version, all was OK, congrats!

If it wasn’t, restart your computer and try again. If it still isn’t working, double-check this tutorial, try to read your JAVA_HOME path, and see if it points to the the bin folder within the downloaded folder’s path.

Steps for Linux/macOS:

  1. Store the extracted files in the Directory Tree:

Then, extract the compressed file appropriate to your OS. In case you can’t or don’t want to use admin permissions, extract it somewhere in your user space (like ~/.openjdk).

If you want a more conventional location, extract it to /usr/local/, which is where software manually installed by the user conventionally goes in POSIX systems.

My command (for Linux) was this one: sudo tar -xf OpenJDK11U-jdk_x64_linux_hotspot_11.0.16.1_1.tar.gz -C /usr/local.

2.   Set JAVA_HOME and add it to PATH:

Set JAVA_HOME to where you extracted your OpenJDK installation. Point it to the OpenJDK directory, not to its /bin subfolder, as JAVA_HOME will not only be used to determine the executables’ location.

This should be located in your shell initialization file. For example, let’s suppose These are the two last lines of my ~/.zshrc file:

   export JAVA_HOME="/usr/local/jdk-11.0.16.1+1"
   export PATH="$JAVA_HOME/bin:$PATH"

3.   Verify Installation

Now, refresh your shell by either sourcing the init file or opening another tab/window.

You can check installation with java -version. If no errors are displayed, congratulations! Time to do some Java’ing.

Wrapping Up

And that’s it! Now you should have OpenJDK installed and ready to use on your machine. Thanks for reading.



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Install and Configure OpenJDK in Windows

Table of Contents

The Oracle JDK license has been changed since the release of Java Standard Edition (JDK 8 and above) on April 16, 2019. While this license change does not impact people using Oracle JDK for personal, development, and training purpose, there are a lot of people who started looking for an alternative option. The use of Oracle JDK in production environment now needs a commercial license to be purchased. However, No-Fee Terms and Conditions (NFTC) still allows the users to use Oracle JDK free of cost (even in production environment) as long as the end product is not distributed for a fee.

I am neither a lawyer nor a licensing expert so I will not discuss the licensing and technical details here. In this article, I will discuss how you can install and configure OpenJDK – a completely free and open-source implementation of the Java SE – in Windows. The main problem with OpenJDK is that it does not provide the installer packages like Oracle JDK. The executable installer packages of Oracle JDK made it incredibly easy for users to install and setup JDK without hassle – particularly in Windows. OpenJDK is available as compressed archives which require manual configuration in Windows. So lets discuss how to install and configure OpenJDK in Windows.

Downloading OpenJDK

The OpenJDK is available for download at https://openjdk.java.net. You can download the compressed archive of a particular build for your operating system as shown in the following screenshot:

OpenJDK Download

Installing OpenJDK

Once you download the compressed archive, the installation is fairly simple. You just need to extract the archive into a folder of your choice. I will extract mine into “C:\Program Files\Java” using the following PowerShell command:

Expand-Archive -Path "$env:USERPROFILE\downloads\openjdk-17.0.2_windows-x64_bin.zip" -DestinationPath "C:\Program Files\Java" -Force

Install OpenJDK

Assuming the OpenJDK archive is located in your downloads folder, this command extracts it to the “C:\Program Files\Java” folder. The destination folder will be automatically created if it doesn’t exist. Next step is to setup the environment variables in Windows so that OpenJDK can be accessed by users and programs the same way as that of Oracle JDK.

Configuring Environment Variables for OpenJDK

To setup the environment variables for OpenJDK, follow these steps:

If you see this error, watch this video to learn how to setup environment variables in Windows. You could also try to setup environment variables using PowerShell commands as shown in the next section.

Configuring Environment Variables for OpenJDK using PowerShell

If the environment variable you created using GUI does not work, you could use the commands mentioned in this section to setup the environment variables using PowerShell commands. The benefit of using this method is that there are less chances of errors.

  • Launch an elevated session of Windows PowerShell console. To do this, right click on Windows PowerShell and select “Run as Administrator” option.
  • Now type the following command and press Enter:
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk-17.0.2", "Machine")

Java Home System Variable
If you do not see any error, it means the system variable is created successfully. Please modify the folder path as per your system.

  • Next step is to create user variable referencing to the Java binaries. To do that, use the following commands:
$path = [System.Environment]::GetEnvironmentVariable("Path","Machine")

[System.Environment]::SetEnvironmentVariable("Path", $path + ";%JAVA_HOME%\bin", "Machine")
  • After running these commands, the Path user variable is updated to include java binaries. To view the Path user variable, you could use the following command:
[System.Environment]::GetEnvironmentVariable("Path","Machine") -Split ";"

Java Configuration using PowerShell
These commands will set the environment variables that are required for Java to work on your Windows system. To verify the setup, launch a new command prompt and type  java --version command and press Enter. This time you should see the Java version configured on your system.

Troubleshooting

If you follow this guide properly but still get the following error:

Error opening registry key 'Software\JavaSoft\Java Runtime Environment'
Error: could not find Java.dll
Error: could not find Java 2 Runtime Environment

Error: could not find Java 2 Runtime Environment

Error: could not find Java 2 Runtime Environment

This error occurs when the previously installed Java SE isn’t properly removed from your system. To fix this error, go to C:\ProgramData directory, locate the directory named Oracle, then rename or delete it. See the screenshot for a reference:

Remove obsolete Java folder from ProgramData

Remove obsolete Java folder from ProgramData

After removing the said directory, run the java -version command again and the error will go away.

Viewing OpenJDK version using java -version command

Viewing OpenJDK version using java -version command

  • How to install windows from ubuntu
  • How to install php on windows
  • How to install windows from linux
  • How to install openssl on windows
  • How to install nvm on windows