https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html
java -version
yum list installed | grep java
#--卸载openjdk 1.7
yum -y remove java-1.7.0-openjdk.x86_64
yum -y remove java-1.7.0-openjdk-headless.x86_64
#--卸载openjdk 1.8
yum -y remove java-1.8.0-openjdk.x86_64
yum -y remove java-1.8.0-openjdk-headless.x86_64
创建安装目录
mkdir /opt/java
下载 JDK 压缩包,上传到服务器
本文下载的版本:jdk-11.0.20_linux-x64_bin.tar.gz
scp -r C:\Users\xx.xx\Downloads\jdk-11.0.20_linux-x64_bin.tar.gz root@xxx.xxx.xxx.xxx:/opt/java
解压
cd /opt/java
tar -zxvf jdk-11.0.20_linux-x64_bin.tar.gz
编辑 /etc/profile
vim /etc/profile
写入环境配置
export JAVA_HOME=/opt/java/jdk-11.0.20
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
更改立即生效
source /etc/profile
[root@ztl home]# source /etc/profile
[root@ztl home]# rm -f /usr/bin/java
[root@ztl home]# ln -s /opt/java/jdk-11.0.20/bin/java /usr/bin/java
[root@ztl home]# ln -s /opt/java/jdk1.8.0_351/bin/java /usr/bin/java
查看 JDK 版本
[root@localhost /]# java -version
java version "11.0.20" 2023-07-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.20+9-LTS-256)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.20+9-LTS-256, mixed mode)
在 Java 8之后,安装的 JDK 不再包含 JRE
# 进入 JDK 安装目录
cd /opt/java/jdk-11.0.20
# 生成 JRE
bin/jlink --module-path jmods --add-modules java.desktop --output jre
[root@localhost jdk-11.0.20]# ls
bin conf include jmods jre legal lib man README.html release