安装jdk
下载jdk1.8——https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
解压
tar -zxvf jdk-8u291-linux-x64.tar.gz
mv jdk1.8.0_291 /opt
添加环境变量
echo "export JAVA_HOME=/opt/jdk1.8.0_291/" >> ~/.bashrc
echo "export CLASSPATH=.:${JAVA_HOME}/lib" >> ~/.bashrc
echo "export PATH=${JAVA_HOME}/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
安装并注册 执行命令
update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_291/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_291/bin/javac 1
update-alternatives --set java /opt/jdk1.8.0_291/bin/java
update-alternatives --set javac /opt/jdk1.8.0_291/bin/javac
update-alternatives --config java
update-alternatives --config javac
测试
java -version
遇到报错
[-] keytool is not in $PATH
install the Java Developer Kit
解决:将keytool添加到环境变量中
find / -name keytool
/opt/jdk1.8.0_291/jre/bin/keytool
/opt/jdk1.8.0_291/bin/keytool
/usr/bin/keytool
export PATH=/opt/jdk1.8.0_291/jre/bin/:$PATH
export PATH=/opt/jdk1.8.0_291/bin/:$PATH