Java 如何在 Ubuntu 下安装 JDK 11?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52504825/
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
How to install JDK 11 under Ubuntu?
提问by Dmitriy Dumanskiy
So Java 11 is out. Does anybody know how to install it (OpenJDK from Oracle) from the command line?
所以 Java 11出来了。有人知道如何从命令行安装它(Oracle 的 OpenJDK)吗?
I would like to see something like it was before for Oracle Java 10:
我想在 Oracle Java 10 之前看到类似的东西:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
P. S. In the similarquestion proposed instruction:
PS在类似问题中提出的指令:
sudo apt-get install openjdk-11-jdk
doesn't work.
不起作用。
采纳答案by 9ilsdx 9rvj 0lo
Now it is possible to install openjdk-11 this way:
现在可以通过这种方式安装 openjdk-11:
sudo apt-get install openjdk-11-jdk
(Previously it installed openjdk-10, but not anymore)
(以前它安装了 openjdk-10,但现在没有了)
回答by Jose Henriquez
I created a Bash script that basically automates the manual installation described in the linked similar question. It requires the tar.gz
file as well as its SHA256 sum value. You can find out more info and download the script from my GitHub project page. It is provided under MIT license.
我创建了一个 Bash 脚本,它基本上自动执行链接的类似问题中描述的手动安装。它需要tar.gz
文件及其 SHA256 总和值。您可以从我的GitHub 项目页面找到更多信息并下载脚本。它是在 MIT 许可下提供的。
回答by Kamal
For anyone running a JDK on Ubuntu and want to upgrade to JDK11, I'd recommend installing via sdkman. SDKMAN is a tool for switching JVMs, removing and upgrading.
对于在 Ubuntu 上运行 JDK 并想要升级到 JDK11 的任何人,我建议通过sdkman安装。SDKMAN 是一个用于切换JVM、移除和升级的工具。
SDKMANis a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates.
SDKMAN是一种用于在大多数基于 Unix 的系统上管理多个软件开发工具包的并行版本的工具。它提供了一个方便的命令行界面 (CLI) 和 API,用于安装、切换、删除和列出候选者。
Install SDKMAN
安装 SDKMAN
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
$ sdk version
Install Java (11.0.3-zulu)
安装 Java (11.0.3-zulu)
$ sdk install java
回答by P. Lion
I came here looking for the answer and since no one put the command for the oracle Java 11 but only openjava 11 I figured out how to do it on Ubuntu, the syntax is as following:
我来这里是为了寻找答案,由于没有人为 oracle Java 11 提供命令而只有 openjava 11 我想出了如何在 Ubuntu 上执行此操作,因此语法如下:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java11-installer
回答by kaniyan
To install Openjdk 11 in Ubuntu, the following commands worked well.
要在 Ubuntu 中安装 Openjdk 11,以下命令运行良好。
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt install openjdk-11-jdk
回答by Jagath Wijesinghe
In Ubuntu, you can simply install Open JDK by following commands.
在 Ubuntu 中,您可以通过以下命令简单地安装 Open JDK。
sudo apt-get update
sudo apt-get install default-jdk
You can check the java version by following the command.
您可以通过以下命令检查java版本。
java -version
If you want to install Oracle JDK 8 follow the below commands.
如果要安装 Oracle JDK 8,请按照以下命令操作。
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
If you want to switch java versions you can try below methods.
如果您想切换java版本,您可以尝试以下方法。
vi ~/.bashrc
and add the following line export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
(path/jdk folder)
vi ~/.bashrc
并添加以下行export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
(路径/jdk 文件夹)
or
或者
sudo vi /etc/profile
and add the following lines
sudo vi /etc/profile
并添加以下几行
#JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export JRE_HOME
export PATH
You can comment on the other version. This needs to sign out and sign back in to use. If you want to try it on the go you can type the below command in the same terminal. It'll only update the java version for a particular terminal.
你可以评论另一个版本。这需要注销并重新登录才能使用。如果您想随时随地尝试,可以在同一终端中键入以下命令。它只会更新特定终端的 java 版本。
source /etc/profile
You can always check the java version by java -version
command.
您可以随时通过java -version
命令检查 java 版本。
回答by Ajay Kumar
We don't need any PPA.. Period ! Get direct, original and official copy of your oracle java straight from oracle. Follow these simple steps.
我们不需要任何 PPA .. 时期!直接从 oracle 获取您的 oracle java 的直接、原始和官方副本。按照这些简单的步骤操作。
Step1: Go to this official link for java 11. - https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
步骤 1:转到 Java 11 的官方链接。 - https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
Step2: Select radio - Accept License Agreement.
步骤 2:选择单选 - 接受许可协议。
Step3: Click jdk-11.0.x_linux-x64_bin.debto download. Here "x" is the update version. If you are not a registered user with Oracle, to download this file, you might be asked to logint/register (it doesnt harm).
Step3:点击jdk-11.0.x_linux-x64_bin.deb下载。这里的“x”是更新版本。如果您不是 Oracle 的注册用户,要下载此文件,可能会要求您登录/注册(这不会造成危害)。
Step4: Install your downloaded .deb file using command line (sudo dpkg -i /path/to/deb/file/jdk-11.0.x_linux-x64_bin.deb) or any gui tool (gdebi etc.). By default the .deb will be installed at this location - /usr/lib/jvm/jdk-11.0.x(x is your downloaded version).
步骤 4:使用命令行(sudo dpkg -i /path/to/deb/file/jdk-11.0.x_linux-x64_bin.deb)或任何 gui 工具(gdebi 等)安装下载的 .deb 文件。默认情况下,.deb 将安装在此位置 - /usr/lib/jvm/jdk-11.0.x(x是您下载的版本)。
Step5: Open a new terminal. Run these comands (tweak is as per your version):
第五步:打开一个新的终端。运行这些命令(根据您的版本进行调整):
cd /usr/lib/jvm/jdk-11.0.x
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-11.0.5/bin/java" 0
exit
Step6: To verify, open a new terminal and issue
步骤 6:要验证,请打开一个新终端并发出
java -version
You should get the output (similar to this):
您应该得到输出(类似于此):
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)
You are all set..!!
你都准备好了..!!
Later you can add JAVA_HOME=/usr/lib/jvm/jdk-11.0.5/ to your .bashrc file.
稍后您可以将 JAVA_HOME=/usr/lib/jvm/jdk-11.0.5/ 添加到您的 .bashrc 文件中。
回答by Som
sudo apt-get install openjdk-11-jdk
须藤 apt-get 安装 openjdk-11-jdk
after this, try
在此之后,尝试
java -version
版本
to make sure java version is 1.11.x, if found old one or different, check below command to see the available jdks,
确保 java 版本是 1.11.x,如果发现旧版本或不同版本,请检查以下命令以查看可用的 jdks,
sudo update-java-alternatives --list
须藤更新-java-alternatives --list
you should see something like below,
你应该会看到类似下面的内容,
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
you can see java 1.11 available from above list, use below command to set java 11 to default,
您可以从上面的列表中看到 java 1.11 可用,使用下面的命令将 java 11 设置为默认值,
sudo update-alternatives --config java
须藤更新替代品--config java
for above command, you will get something like below and also, will ask for an option to set,
对于上面的命令,你会得到类似下面的内容,并且会要求设置一个选项,
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
*2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/jdk1.8.0_211/bin/java 0 manual mode
Press to keep the current choice[*], or type selection number:
替代 java 有 3 种选择(提供 /usr/bin/java)。
选择路径优先状态
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 自动模式
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 手动模式
*2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081手动模式
3 /usr/lib/jvm/jdk1.8.0_211/bin/java 0 手动模式
按 保持当前选择[*],或输入选择编号:
you can select desired selection number, my case it's 0
您可以选择所需的选择编号,我的情况是 0
for javac,
对于 javac,
sudo update-alternatives --config javac
须藤更新替代品 --config javac
will result something like below,
会产生类似下面的结果,
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
*2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
3 /usr/lib/jvm/jdk1.8.0_211/bin/javac 0 manual modePress to keep the current choice[*], or type selection number:
替代 javac 有 3 种选择(提供 /usr/bin/javac)。
选择路径优先状态
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 自动模式
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 手动模式
*2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 手动模式
3 /usr/lib/jvm/jdk1.8.0_211/bin/javac 0 手动模式按 保持当前选择[*],或输入选择编号:
in my case, it's 0 again
在我的情况下,它又是 0
after above steps, try
完成上述步骤后,尝试
java -version
版本
it will display something like below,
它会显示如下内容,
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed > mode, sharing)
openjdk 版本“11.0.4” 2019-07-16
OpenJDK 运行时环境(构建 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64 位服务器 VM(构建 11.0.4+11-post-Ubuntu-1ubuntu218.04.3,混合 > 模式,共享)