1.更新程序包
yum update
2.檢查系統(tǒng)是否已安裝java
java -version
3.若有,使用yum remove進(jìn)行刪除
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.在下載目錄執(zhí)行安裝命令
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.編輯內(nèi)容
#!/bin/bash
JAVA_HOME=/opt/software/java/jdk1.8.0_172-amd64/
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
export CLASSPATH=.
9.執(zhí)行命令训堆,使java.sh可運(yùn)行
chmod +x /etc/profile.d/java.sh
10.執(zhí)行命令王滤,設(shè)置永久環(huán)境變量
source /etc/profile.d/java.sh