419

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?

Gili
  • 86,244
  • 97
  • 390
  • 689
  • 1
    Changing the registry was never actually needed. And when not manipulating the system, you don’t need an uninstaller either. – Holger Sep 26 '18 at 07:17
  • [Difference between installing an JDK and using the dump](https://stackoverflow.com/questions/8193008) – Mikhail Kholodkov Sep 26 '18 at 10:38
  • @MikhailKholodkov The answers are outdated and no longer relevant of JDK 11. – Robert Sep 26 '18 at 18:36
  • For the future it would be good having an installer/updater. May be we should start an open source project or is there an already existing project? – Robert Sep 26 '18 at 18:38
  • @Robert What's exactly outdated in those answers? Output directory layout has changed a bit, but nothing else. Question covers the difference between installation and pure "copying" of JDK. It seems totally relevant. – Mikhail Kholodkov Sep 26 '18 at 20:06
  • @Holger How are native launchers (e.g. IDE) supposed to locate the JDK without a registry key or default install location? The only option that is left is to bundle a JDK with each native application. Is the concept of a global JDK dead? – Gili Sep 26 '18 at 21:06
  • 1
    @Gili using JAVA_HOME environment variable or through direct path in config like IntelliJ IDEa does it? – Mikhail Kholodkov Sep 26 '18 at 21:25
  • 19
    There is a community project [ojdkbuild](https://github.com/ojdkbuild/ojdkbuild) which provides Windows installers for OpenJDK. JDK 11 is not available there yet but I hope we will get it soon. – ZhekaKozlov Sep 27 '18 at 03:48
  • 1
    @Gili http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Find_the_JVM note how registry does not appear anywhere… – Holger Sep 27 '18 at 06:06
  • 2
    @Robert well, without a browser plugin, control panel, automatic update tool, nor the ask toolbar crapware, there is not so much left to install. – Holger Sep 27 '18 at 06:32
  • Just download the .msi from https://github.com/ojdkbuild/ojdkbuild/releases – jfleach Apr 23 '19 at 16:40
  • @jfleach ojdkbuild is a totally different thing, from totally different people. – Franklin Yu Aug 19 '19 at 19:13
  • Jedit and Netbeans use the registry. – js2010 Feb 26 '20 at 20:45
  • And Eclipse.... – js2010 Feb 28 '20 at 15:44
  • Does this answer your question? [OpenJDK availability for Windows OS](https://stackoverflow.com/questions/5991508/openjdk-availability-for-windows-os) – Bernhard Stadler May 09 '21 at 06:10
  • @BernhardStadler No. This question deals exclusively with the installation of OpenJDK, not the availability. – Gili May 10 '21 at 17:39
  • @Gili The answers to the question of availabilty for Windows of course also include the availability of installers for Windows. You just need to scroll down a bit. – Bernhard Stadler May 11 '21 at 18:26

12 Answers12

574
  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
  • 124,188
  • 49
  • 220
  • 267
Lior Bar-On
  • 10,784
  • 5
  • 34
  • 46
  • 10
    Don't forget the registry entries, which are e.g. used by Launch4j for finding installed jre/jdk. – Robert Sep 27 '18 at 11:39
  • How would you do if you were using ubuntu – Wil Ferraciolli Sep 27 '18 at 13:20
  • @Robert - sorry, but this is a specific tool worth its own discussion. – Lior Bar-On Sep 27 '18 at 19:21
  • @WilFerraciolli I added a tag to the question to clarify that it is Windows-specific. I recommend opening a separate question for Ubuntu. – Gili Sep 28 '18 at 04:54
  • 2
    @Lior: This is just one program I know that uses the registry entries. There may be dozens or hundred of other programs using these registry entries, too. – Robert Sep 28 '18 at 07:32
  • 5
    It may be so, but: a. I worked with Java since ver 1.1 without setting the registry - so it is not a must. b: the windows registry is commonly considered as a mechanism to avoid (e.g. https://blog.codinghorror.com/was-the-windows-registry-a-good-idea/) - hence I don't think it should be used, if not specifically needed. e.g. - a mistake setting a value in it can lead to a hard-to-recover-from error. – Lior Bar-On Sep 28 '18 at 15:31
  • I have installed OpenJDK on Windows 10 and set JAVA_HOME and PATH. On the Windows command line, I can do "javac -version" and "jshell", but not "java -version". That's strange. IntelliJ works,so I think I'm OK. – radumanolescu Oct 07 '18 at 18:49
  • 30
    > *You can point the JAVA_HOME to the folder where you have multiple JDK installations*. This is completely wrong. Many programs and scripts assume JAVA_HOME points to default java installation (jdk or jre) and they search for binaries under "%JAVA_HOME%\bin". So you CANNOT point JAVA_HOME to folder with *multiple* jdk installations. Instead you can add to Path the value "%JAVA_HOME%\bin;" and then (when new JDK installed) you can update JAVA_HOME only – kool79 Dec 04 '18 at 11:29
  • @Robert what are these registry entries launch4j is looking for? – sarkasronie Mar 20 '19 at 11:06
  • 2
    @sarkasronie See launch4j source code: https://sourceforge.net/p/launch4j/git/ci/Release_launch4j-3_12/tree/head_src/head.c#l630 (under HKEY_LOCAL_MACHINE) – Robert Mar 20 '19 at 13:38
  • 2
    As @craftwar mentioned in the downvoted answer below one may experience the following error when running java --version after following the instructions from the above answer: Error: opening registry key 'Software\JavaSoft\Java Runtime Environment' Error: could not find java.dll Error: Could not find Java SE Runtime Environment. This is due to Oracle JDK uninstaller not removing the files in "C:\ProgramData\Oracle", once I removed the "Oracle" directory everything started working as expected. – tolkinski Apr 11 '19 at 19:58
  • 3
    Please add that you have to move your Java11 PATH entry to the beginning of the PATH. This to override some (multiple!) path settings to "...\Oracle\Java\javapath". If you don't do this, the test can fail. – Roeland Van Heddegem Apr 24 '19 at 13:52
  • 1
    Would be nice if these steps were included in the Installation Instructions on the official OpenJDK website... all it says there is "download and unzip it". I don't understand why they don't mention anything about adding to PATH and setting JAVA_HOME... – Kat Feb 20 '20 at 10:27
  • @RoelandVanHeddegem wow, great tip, thanks for saving me time lol – FDM Jan 25 '21 at 20:51
  • This is the correct answer. I guess this is a lot more obvious to those of us accustomed to adding values to $PATH on real operating system. – Nick Mar 22 '21 at 21:13
  • Can I add the path for Java 8 as well with Java 11 path ? – Seeschon Aug 17 '21 at 14:19
  • wondering why this was not working for me. Issue: my cmd was running on a C from one hdd and I was placing jdk on D: that was on another hdd – veritas Apr 07 '22 at 08:33
279

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...).

Pimgd
  • 5,983
  • 1
  • 30
  • 45
  • 35
    Although the accepted answer is correct, this is a much more convenient way to install any version of the JDK/JRE – optevo Oct 16 '19 at 04:00
  • @AJDhaliwal I have edited the answer to more prominently display Eclipse Adoptium. – Pimgd Sep 21 '22 at 09:00
41

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.

Tobias
  • 2,089
  • 2
  • 26
  • 51
  • 4
    Note that this would install latest version: openjdk-12.0.2_windows-x64 – Vadzim Sep 09 '19 at 07:27
  • 1
    in case you have other java versions installed you might want to check the path variables and remove/modify the old. – Ketu Oct 17 '19 at 06:06
  • 2
    @Vadzim choco install openjdk11 as of today without mentioning the version, it installs openjdk-13 and just to note, it will use the AdoptOpenJDK as in other answers – F.I.V Mar 14 '20 at 14:27
  • As a note for this method, jdk11 is no longer supported and kept up to date. Be sure to use "openjdk11" not "jdk11". Per the maintainer: "Sorry for all. As Oracle requires us to login OTN to install JDK 11, I can't support chocolaty JDK 11 package anymore. Sorry. I requested remove this JDK 11 package. Please use open jdk package." – Newbie12345 Dec 30 '20 at 21:12
  • I installed it and when i try `java -version` I get 'java: The term 'java' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.' Is there something else I need to do? – Godstime Osarobo Jun 20 '21 at 00:52
  • 1
    @GodstimeOsarobo You may need to close & reopen your shell window (cmd/powershell), as only then the PATH environment variable is updated appropriately. – Tobias Jun 21 '21 at 06:17
  • 1
    You can use [chocolatey](https://community.chocolatey.org) and specifically ask for OpenJDKv11: `choco install openjdk --version=11.0`. As noted [here](https://community.chocolatey.org/packages/openjdk/11.0). – idrositis May 02 '22 at 14:25
  • Chocolatey install script for elevated PowerShell (all 1 line): Set-ExecutionPolicy Bypass -Scope Process -Force; ` iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) – jrbe228 Jun 03 '22 at 17:06
  • this will no longer work. ` The remote file either doesn't exist, is unauthorized, or is forbidden for url 'https://download.java.net/java/GA/jdk11/28/GPL/openjdk-11+28_windows-x64_bin.zip'` – 1mike12 Nov 03 '22 at 21:24
  • @1mike12 It seems as the old versions are deprecated. Newer versions like 18 or 19 should work. – Tobias Nov 07 '22 at 15:32
23

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

Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
  • 4
    For me those builds didn't set the PATH variables properly. At lease I can't issue `java -version` and get the desired output. – hannes101 Jan 16 '19 at 08:45
  • 1
    I can't find OpenJDK msi. I'll do script and share it in an answer later today that extracts and sets PATH and JAVA_HOME for the machine. – vezenkov Jan 16 '19 at 13:05
  • 1
    @vezenkov: Update the answer here (it's community wiki for a reason) and/or open an issue with the project, please. – Martin Schröder Jan 16 '19 at 13:08
  • To add to the accepted answer if you were upgrading from a previous version I had to even restart the server to see the openjdk version get updated on the command line. – desiguy Nov 26 '19 at 17:02
5

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.

Swapnil
  • 1,004
  • 1
  • 13
  • 21
3

For Java 12 onwards, official General-Availability (GA) and Early-Access (EA) Windows 64-bit builds of the OpenJDK (GPL2 + Classpath Exception) from Oracle are available as tar.gz/zip from the JDK website.

If you prefer an installer, there are several distributions. There is a public Google Doc and Blog post by the Java Champions community which lists the best-supported OpenJDK distributions. Currently, these are:

Bernhard Stadler
  • 1,725
  • 14
  • 24
2

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
jfk
  • 4,335
  • 34
  • 27
1

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.

David Airapetyan
  • 5,301
  • 4
  • 40
  • 62
1

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

Prince
  • 20,353
  • 6
  • 39
  • 59
1

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.

d3r3kk
  • 3,465
  • 3
  • 18
  • 22
0

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

Engr.Aftab Ufaq
  • 3,356
  • 3
  • 21
  • 47
0

Try this also. choco install -y microsoft-openjdk11

Nabeel Ali
  • 74
  • 8