1.先確定當(dāng)前服務(wù)器有沒有安裝java
[sandwich@centos-elk ~]$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
2.確定java安裝地址
[sandwich@centos-elk ~]$ which java
/usr/bin/java
[sandwich@centos-elk ~]$ ls -lr /usr/bin/java
lrwxrwxrwx. 1 root root 22 Oct 31 07:45 /usr/bin/java -> /etc/alternatives/java
[sandwich@centos-elk ~]$ ls -lrt /etc/alternatives/java
lrwxrwxrwx. 1 root root 73 Oct 31 07:45 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/jre/bin/java
由此可見jdk安裝在/usr/lib/jvm下
那我新下載的jdk 17也安裝到這個地址下好了净薛。
3.下載jdk 17并放到合適的位置上
[sandwich@centos-elk Downloads]$ wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
[sandwich@centos-elk Downloads]$ tar xf jdk-17_linux-x64_bin.tar.gz
[sandwich@centos-elk Downloads]$ mv jdk-17.0.3/ /usr/lib/jvm
4.配置環(huán)境變量
[sandwich@centos-elk Downloads]$ sudo vi /etc/profile
#添加以下內(nèi)容
[sandwich@centos-elk Downloads]$ tail -n 4 /etc/profile
export JAVA_HOME=/usr/lib/jvm/jdk-17.0.3
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[sandwich@centos-elk Downloads]$ source /etc/profile
5.驗證安裝
[sandwich@centos-elk Downloads]$ java -version
java version "17.0.3" 2022-04-19 LTS
Java(TM) SE Runtime Environment (build 17.0.3+8-LTS-111)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.3+8-LTS-111, mixed mode, sharing)