如何在 Windows 上安装 OpenJDK 11?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52511778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:05:02  来源:igfitidea点击:

How to install OpenJDK 11 on Windows?

windowsjava-11

提问by Gili

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

过去,Oracle 过去常常发布适用于 Windows 的可执行安装程序,它可以:

  • Unpack files
  • Add registry keys indicating the installed version and path
  • Add the JRE to the system PATH
  • Register an uninstaller with Windows.
  • 解压文件
  • 添加指示安装版本和路径的注册表项
  • 将 JRE 添加到系统 PATH
  • 向 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.

从 Java 11 开始,Oracle 的免费版 Java ( Oracle OpenJDK) 似乎不包含安装程序。它只是一个包含二进制文件的 zip 文件。

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

我们应该如何在 Windows 上安装 OpenJDK 11,因为上述集成不再存在?他们不是必须的吗?

回答by Lior Bar-On

  1. Extract the zip file into a folder, e.g. C:\Program Files\Java\and it will create a jdk-11folder (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 binsub-folder).
    • Click OK.
    • Click Apply Changes.
  4. Configure the JDK in your IDE (e.g. IntelliJ or Eclipse).
  1. 将 zip 文件解压缩到一个文件夹中,例如C:\Program Files\Java\,它将创建一个jdk-11文件夹(其中 bin 文件夹是一个直接的子文件夹)。您可能需要管理员权限才能将 zip 文件解压缩到此位置。

  2. 设置路径:

    • 选择控制面板,然后选择系统。
    • 单击高级,然后单击环境变量。
    • 在系统变量中的PATH变量中添加JDK安装的bin文件夹的位置。
    • 以下是 PATH 变量的典型值: C:\WINDOWS\system32;C:\WINDOWS;"C:\Program Files\Java\jdk-11\bin"
  3. 设置 JAVA_HOME:

    • 在系统变量下,单击新建。
    • 输入变量名作为 JAVA_HOME。
    • 输入变量值作为JDK的安装路径(不bin带子文件夹)。
    • 单击确定。
    • 单击应用更改。
  4. 在您的 IDE(例如 IntelliJ 或 Eclipse)中配置 JDK。

You are set.

你准备好了。

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

要查看它是否有效,请打开命令提示符并键入java -version并查看它是否打印了您新安装的 JDK。

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

如果要卸载 - 只需撤消上述步骤。

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

注意:您也可以指向JAVA_HOMEJDK 安装的文件夹,然后将PATH变量设置为%JAVA_HOME%\bin. 因此,当您想更改 JDK 时,您只需更改JAVA_HOME变量并保持PATH原样。

回答by Pimgd

AdoptOpenJDKis a new website hosted by the java community. You can find .msi installers for OpenJDK 8 through 12 there, which will perform all the things listed in the question (Unpacking, registry keys, PATH variable updating (and JAVA_HOME), uninstaller...).

AdoptOpenJDK是一个由java 社区托管的新网站。您可以在那里找到 OpenJDK 8 到 12 的 .msi 安装程序,它们将执行问题中列出的所有内容(解包、注册表项、PATH 变量更新(和 JAVA_HOME)、卸载程序...)。

回答by Tobias

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

使用Chocolatey 包管理器。它是一个类似于 npm 的命令行工具。安装好后,使用

choco install openjdk

in an elevated command prompt to install OpenJDK.

在提升的命令提示符下安装 OpenJDK。

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.

使用起来非常简单,尤其有助于升级到最新版本。无需手动摆弄路径环境变量。

回答by Reinstate Monica - M. Schr?der

From the comment by @ZhekaKozlov: ojdkbuildhas OpenJDK builds (currently 8 and 11) for Windows (zipand msi).

来自@ZhekaKozlov 的评论:ojdkbuild具有适用于 Windows(zipmsi)的OpenJDK 构建(目前为 8 和 11 )。

回答by 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.

您可以使用亚马逊 Corretto。可以免费使用 OpenJDK 的多平台、生产就绪发行版。它带有长期支持,包括性能增强和安全修复。在此处查看安装说明。

You can also check Zulufrom Azul.

您还可以从Azul查看Zulu

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

我想在这里强调的另一件事是 Amazon Corretto 和 Zulu 都符合 TCK 标准。您可以在此处此处查看 OpenJDK 构建比较。

回答by craftwar

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.

Oracle Java 卸载程序不会删除所有文件。
检查“C:\ProgramData\Oracle”是否存在,子目录中有一些java文件。(例如:java.exe、javaw.exe)
将其删除以防止执行错误的 java 文件。