1. 从 Oracle 官网 (http://www.oracle.com/technetwork/Java/javase/downloads/jdk8-downloads-2133151.html)下载 JDK:jdk-8u112-linux-i586.tar.gz
2. 解压JDK文件到新建目录
tar -xzvf jdk-8u112-Linux-i586.tar.gz
cp -R jdk1.8.0_112/ ../install/java
3. 设置环境变量:
#set Java environment
export JAVA_HOME=/home/nick/install/java/jdk1.8.0_112
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
4. 设置默认JDK
sudo update-alternatives --install /usr/bin/java java /home/nick/install/java/jdk1.8.0_112/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /home/nick/install/java/jdk1.8.0_112/bin/javac 300
5.验证
java -version
原文链接:https://www.f2er.com/ubuntu/355405.html