ChatGPT解决这个技术问题 Extra ChatGPT

How to install OpenJDK 11 on Windows?

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?

Changing the registry was never actually needed. And when not manipulating the system, you don’t need an uninstaller either.
@Gili using JAVA_HOME environment variable or through direct path in config like IntelliJ IDEa does it?
There is a community project ojdkbuild which provides Windows installers for OpenJDK. JDK 11 is not available there yet but I hope we will get it soon.
@Gili wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Find_the_JVM note how registry does not appear anywhere…
@Robert well, without a browser plugin, control panel, automatic update tool, nor the ask toolbar crapware, there is not so much left to install.

G
Georg Schölly

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


Don't forget the registry entries, which are e.g. used by Launch4j for finding installed jre/jdk.
@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.
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. 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.
> 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
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.
P
Pimgd

AdoptOpenJDK is a new 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...).

As of writing, AdoptOpenJDK still hosts the latest versions of OpenJDK, but in the future, it is planned for new releases to be available at Eclipse Adoptium.


Although the accepted answer is correct, this is a much more convenient way to install any version of the JDK/JRE
T
Tobias

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.


Note that this would install latest version: openjdk-12.0.2_windows-x64
in case you have other java versions installed you might want to check the path variables and remove/modify the old.
@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
@GodstimeOsarobo You may need to close & reopen your shell window (cmd/powershell), as only then the PATH environment variable is updated appropriately.
You can use chocolatey and specifically ask for OpenJDKv11: choco install openjdk --version=11.0. As noted here.
2
2 revs

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


For me those builds didn't set the PATH variables properly. At lease I can't issue java -version and get the desired output.
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: Update the answer here (it's community wiki for a reason) and/or open an issue with the project, please.
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.
S
Swapnil

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.


B
Bernhard Stadler

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:

AdoptOpenJDK has been superseded by Adoptium/Temurin (Hotspot) and IBM Semeru (OpenJ9)

Adoptium Temurin

Amazon Corretto

IBM Semeru (with OpenJ9 JVM)

Liberica from Bellsoft

Microsoft Build of OpenJDK

OpenLogic OpenJDK

Red Hat OpenJDK

SAPMachine (backed by SAP)

Zulu Community (backed by Azul Systems)


D
David Airapetyan

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.


P
Prince

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

https://i.stack.imgur.com/EVgyk.png