1.先确定当前服务器有没有安装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.配置环境变量
[sandwich@centos-elk Downloads]$ sudo vi /etc/profile
#添加以下内容
[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)
|