(1) 查看CentOS自带的Java环境
yum list installed |grep java
(2)卸载现有Java环境
yum -y remove java-1.8.0-openjdk*
yum -y remove tzdata-java*
(3)查看yum库中的Java安装包
yum -y list java*
![[1635777864155-ba45a868-44ef-4a4c-acb5-5129b456972f.png]]
(4)安装JDK(没有报错,即安装成功)
yum -y install java-1.8.0-openjdk*
(5)查看Java安装的路径
which java
(6)添加Java环境变量
echo "
export JAVA_HOME=/usr/lib/jvm/java-1.8.0 \
export JRE_HOME=$JAVA_HOME/jre \
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin \
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib \
" >> /etc/profile
source /etc/profile
(7)检查Java
安装和配置情况
# 出现安装对应的版本号则安装成功
java -version
标签:Java,JDK,CentOS,java,export,yum,HOME,JAVA,在线
From: https://blog.51cto.com/u_15086327/6215257