1.更新程序包
yum update
2.检查系统是否已安装java
java -version
3.若有,使用yum remove进行删除
4.下载安装包
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-linux-x64.rpm"
5.在下载目录执行安装命令
rpm -ivh jdk-8u172-linux-x64.rpm
6.将java放在"/opt/software"中
mv /usr/java /opt/software
7.在"/etc/profile.d"下新建"java.sh"
vim /etc/profile.d/java.sh
8.编辑内容
#!/bin/bash
JAVA_HOME=/opt/software/java/jdk1.8.0_172-amd64/
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
export CLASSPATH=.
9.执行命令,使java.sh可运行
chmod +x /etc/profile.d/java.sh
10.执行命令,设置永久环境变量
source /etc/profile.d/java.sh