1. 添加ppa
$sudo add-apt-repository ppa:webupd8team/Java(ORACLE)
$sudo add-apt-repository ppa:openjdk-r/ppa (OpenJDK)
2. 安装 openjdk-8-jdk
$sudo apt-get update
$sudo apt-get install openjdk-8-jdk
3. 只对特定用户user采用java 8
$sudo update-alternatives --config java
选择非1.8
$sudoupdate-alternatives --config javac
选择非1.8
user@~$ vim .bashrc
添加:
#export JAVA_HOME=/usr/lib/jvm/java-8-oracle (ORACLE)
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 (OpenJDK)
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
user@~$ source .bashrc
user@~$ java -version
openjdk version "1.8.0_111" OpenJDK Runtime Environment (build 1.8.0_111-8u111-b14-3~14.04.1-b14) OpenJDK 64-Bit Server VM (build 25.111-b14,mixed mode)