1.从官网下载jdk包,Java Archive Downloads - Java SE 8u211 and later
2.创建java目录并上传jdk包
mkdir -p /home/local/java
3.解压jdk包
cd /home/local/java
tar -zxvf /home/local/java/jdk-8u381-linux-x64.tar.gz
4.配置环境变量
vim /etc/profile
i
export JAVA_HOME=/home/local/java/jdk1.8.0_381
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
esc
:wq #保存退出
5.重新加载配置文件
source /etc/profile
6.查看安装是否成功
java -version
javac
java
7.卸载jdk
vim /etc/profile
光标移到相关环境变量配置首行,dd删除行
esc
:wq
source /etc/profile
java -version