1. 去Oracle官方网站:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 下载jdk对应版本,如:jdk-8u171-linux-x64.tar.gz
2. sudo tar -zxf jdk-8u171-linux-x64.tar.gz /usr/local,将jdk解压到/usr/local中
3.设置环境变量,在.zshrc(zsh)或/etc/profile(bash)中添加如下环境变量:
export JAVA_HOME=/usr/local/jdk1.8.0_171
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$PATH
4.更改java环境配置
sudo update-alternatives --install "/usr/bin/java" "java" "/home/goodong/Desktop/jdk1.8.0_102/bin/java" 1 (设置JRE可用)
sudo update-alternatives --install "/usr/bin/javac" "javac" "/home/goodong/Desktop/jdk1.8.0_102/bin/javac" 1 (设置JDK可用)
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/home/goodong/Desktop/jdk1.8.0_102/bin/javaws" 1 (设置Java Web可用)
sudo update-alternatives --set java /home/goodong/Desktop/jdk1.8.0_102/bin/java (设置Java运行时环境)
sudo update-alternatives --set javac /home/goodong/Desktop/jdk1.8.0_102/bin/javac (设置Javac编译器)
sudo update-alternatives --set javaws /home/goodong/Desktop/jdk1.8.0_102/bin/javaws(设置Java Web运行 )
5.利用java -version 和 javac -version测试是否可用
原文地址:https://www.cnblogs.com/zhchy89/p/8994365.html