如何在 Ubuntu 下安装 JDK 10?更新:JDK 11 现已上市对于 JDK 10
如何在 Ubuntu 上安装 Java Development Kit (JDK) 10?
Oracle帮助中心上的安装说明仅解释了如何在Linux平台上下载和提取存档,而无需任何系统设置。
如何在 Ubuntu 上安装 Java Development Kit (JDK) 10?
Oracle帮助中心上的安装说明仅解释了如何在Linux平台上下载和提取存档,而无需任何系统设置。
sudo apt-get install openjdk-11-jdk
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
然后设置为默认值:
sudo apt-get install oracle-java10-set-default
最后验证安装:
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
来源: Linux Uprising
下载 OpenJDK 10 二进制文件 for Linux。
解压缩下载的存档:
tar xzvf openjdk-10_linux-x64_bin.tar.gz
将解压缩的归档文件移动到系统保存已安装的 JDK 的位置:
sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/
添加新的 Java 备选方案:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1
更新系统的 java 备选方案并选择 JDK 10:
$ sudo update-alternatives --config java
here are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode
* 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number:
和
$ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 auto mode
1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-10-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
通过以下方式验证您的安装:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
和
$ javac --version
javac 10
做
如果您更喜欢Oracle的JDK,请下载它并按照上面显示的安装步骤进行操作。
我发现 SdkMan!是一个非常有用的工具,因为它提供了一种从 shell 管理 JDK的便捷方法。
例如,安装后,您可以:
sdk install java 10.0.2-open
Downloading: java 10.0.2-open
In progress...
################# 12,3%
sdk use java 10.0.2-open
Using java version 10.0.2-open in this shell.
sdk list java
===================================================================
Available Java Versions
===================================================================
9.0.4-open
+ 8u161-oracle
8.0.191-oracle
> + 8.0.171-oracle
7.0.191-zulu
12.ea.15-open
11.0.1-open
10.0.2-open
1.0.0-rc8-graal
===================================================================
+ - local version
* - installed
> - currently in use
=======================================================================