Building dependency tree
Reading state information... Done
Package openjdk-7-jdk is not available,butis referred to by another package.
This may mean that the package is missing,has been obsoleted,or
is only available from another source
E: Package 'openjdk-7-jdk' has noinstallation candidate
1.安装openjdk-7-jdk
是因为Ubuntu16.04的安装源已经默认没有openjdk7了,所以要自己手动添加仓库,如下:
(1) sudoadd-apt-repository ppa:openjdk-r/ppa
添加oracle openjdk ppa source,提示:
sudo: add-apt-repository: command not found
改为用add-apt-repository ppa:openjdk-r/ppa,提示
The program 'add-apt-repository' iscurrently not installed. You can install it by typing:
apt install software-properties-common
很清楚地告诉我们没有安装'add-apt-repository,接着采用apt install software-properties-common安装。
(2) sudoapt-get update更新软件列表
这个命令,会访问源列表(/etc/apt/sources.list)里的每个网址,并读取软件列表,然后保存在本地电脑
sudo apt-get install openjdk-7-jdk // OpenJdk 7安装
2.查看安装openjdk版本
已安装了openjdk-7-jdk和openjdk-8-jdk
java -version查看当前选中的版本,内容如下:
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12,mixed mode)
通过ll /etc/alternatives/java命令看结果:
lrwxrwxrwx 1 root root 46 Feb 17 22:05/etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java*
查看已注册列表update-alternatives --display java
java - manual mode
link best version is /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
link currently points to /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
linkjava is /usr/bin/java
slave java.1.gz is /usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java- priority 1071
slave java.1.gz:/usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java- priority 1081
slave java.1.gz:/usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
3.选择jdk版本
sudo update-alternatives --config java
sudo update-alternatives --config javac