1. 下载最新的JAVA JDK
jdk-8u91-linux-x64
2. 解压缩文件并移动至/opt
tar -xzvf jdk-8u91-linux-x64.tar.gz
mv jdk1.8.0_91 /opt
cd /opt/jdk1.8.0_91
3. 设置环境变量
1)执行 gedit ~/.bashrc
, 并添加下列内容
# install JAVA JDK
export JAVA_HOME=/opt/jdk1.8.0_91
export CLASSPATH=.:${JAVA_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
2)执行
source ~/.bashrc
4. 安装并注册
执行:
update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_91/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_91/bin/javac 1
update-alternatives --set java /opt/jdk1.8.0_91/bin/java
update-alternatives --set javac /opt/jdk1.8.0_91/bin/javac
查看结果:
update-alternatives --config java
update-alternatives --config javac
5. 测试
java -version
#output
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
转载自【点击】