在Linux上安装Java 10

摘要: 想要尝鲜Java 10,又不想在自己机器上安装,于是在虚拟的Linux上安装了Java 10. 使用Ubuntu 14.04系统。

1.下载Linux的安装包OpenJDK 10 . 不到200M的压缩包。
这里写图片描述
或者Oracle官方版本:
这里写图片描述

2.解压安装包

tar xzvf openjdk-10_linux-x64_bin.tar.gz

3.将安装包移动到之前安装其他JDK的目录(方便管理)

sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/

4.添加新的Java alternative

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

5.选择默认的Java版本

$ 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  to keep the current choice[*], or type selection number: 

选择Java-10,

$ 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  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

6.验证是否安装正确

$ 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)

7.也可以直接使用Java 10,而不配置Java alternative

$ /usr/lib/jvm/java-10-oracle/bin/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)

你可能感兴趣的:(Java)