转载自:https://blog.csdn.net/huayimy/article/details/130273362
一、安装JDK1.8
1、直接使用下面的地址下载java 1.8:
https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
2、建立目录,将下载的jdk的安装包复制过去并进行解压
sudo mkdir -p /usr/local/java
cp jdk-8u202-linux-x64.tar.gz /usr/local/java
cd /usr/local/java
sudo tar xzvf jdk-8u202-linux-x64.tar.gz
3、配置环境变量(注意下面的版本号要与自己下载的相同)
打开文件/etc/profile
bash
cat /etc/profile
JAVA_HOME=/usr/local/java/jdk1.8.0_202
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
4、通知系统Java的位置
cpp
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_202/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_202/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_202/bin/javaws" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_202/bin/javaws" 1
5、重新载入profile
bash
source /etc/profile
6、切换JDK版本
bash
update-alternatives --config java
在对应的版本前面输入编号后按回车键即可