yum list installed | grep jdk
rpm -qa | grep java
#2.卸载已安装的 JDK
yum -y remove java-1.8.0-open*
yum -y remove tzdata-java.noarch
rpm -qa | grep java | xargs rpm -e --nodeps
#3.安装 JDK
yum install -y java-1.8.0-openjdk*
#4.查看 JDK 安装结果
java -version
#5.获取时间
TIME_FLAG=date +%Y%m%d_%H%M%S
#6.备份配置文件
cp /etc/profile /etc/profile.bak_$TIME_FLAG
#7.修改配置文件,配置系统变量
cat >> /etc/profile << end
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
JRE_HOME=
J
A
V
A
H
O
M
E
/
j
r
e
C
L
A
S
S
P
A
T
H
=
.
:
JAVA_HOME/jre CLASS_PATH=.:
JAVAHOME/jreCLASSPATH=.:JAVA_HOME/lib/dt.jar:
J
A
V
A
H
O
M
E
/
l
i
b
/
t
o
o
l
s
.
j
a
r
:
JAVA_HOME/lib/tools.jar:
JAVAHOME/lib/tools.jar:JRE_HOME/lib
PATH=
P
A
T
H
:
PATH:
PATH:JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
end
#8.使配置生效
source /etc/profile
#9.打印 JDK 配置信息
echo $JAVA_HOME
echo $PATH
echo $CLASSPATH