How to install OpenJDK 11 on Windows?

2019-01-30 03:50发布

问题:

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?

回答1:

  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 point the JAVA_HOME to the folder where you have multiple JDK installations and then set the PATH variable to a certain JDK. So when you want to change the JDK you change only the PATH variable and leave JAVA_HOME as it is.



回答2:

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



回答3:

Oracle Java uninstaller doesn't remove all files.
Check if "C:\ProgramData\Oracle" exists, there is some java files in subdirectory. (ex: java.exe, javaw.exe)
Remove it to prevent executing wrong java files.