CentOS7 下安装 JDK

一、卸载系统自带的 OpenJDK

1
2
3
4
5
6
7
8
9
10
11
# 查看
[root@docker ~]# java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

# 卸载
rpm -qa | grep openjdk | xargs rpm -e --nodeps

# 确认
java -version

二、下载解压

1
2
3
4
5
# 下载
wget https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz

# 解压
tar -zxvf ./jdk-8u202-linux-x64.tar.gz -C /usr/local/

三、配置环境变量

1
2
3
4
5
6
7
8
9
# vim /etc/profile

# Java Environment
export JAVA_HOME=/usr/local/jdk1.8.0_202
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin

# 使环境变量文件生效
source /etc/profile

四、测试

1
2
3
4
[root@localhost local]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)