How to upgrade Java Version on Centos

背景:

log4j漏洞,公司IT对个人虚机进行了扫描,报告出我的部分虚机存在log4j version 为1.2.17,可能会受到影响,需要我们自行处理下。所以想着升级下java的版本, remove掉之前的老版本1.8,在看一下后续还会不会被扫出来.

[root@server2 ~]#  yum list installed | grep log4j
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
log4j.noarch                          1.2.17-16.el7_4                  @anaconda
[root@server2 ~]# 

Centos Java upgrade to 1.11 from 1.8

  1. 检查下java的版本,使用的是openjdk版本是1.8;openjdk和Oracle的Java是有点区别的,Oracle与OpenJDK之间的区别介绍了它们的区别,所以本文后续介绍的openjdk的升级。
[root@server2 ~]# java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

2. 搜索java-11可安装的包:

[root@server2 ~]# sudo yum search java-11
Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Determining fastest mirrors
 * base: mirror.newmediaexpress.com
 * epel: mirrors.bestthaihost.com
 * extras: centos.usonyx.net
 * updates: mirror.aktkn.sg
======================================================= N/S matched: java-11 ========================================================
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.i686 : OpenJDK Demos 11
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.i686 : OpenJDK Development Environment 11
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in a single archive
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in a single archive
java-11-openjdk-jmods.i686 : JMods for OpenJDK 11
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.i686 : OpenJDK Source Bundle 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.i686 : OpenJDK libraries for static linking 11
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking

3. 安装2个包,java-11-openjdk.x86_64 and java-11-openjdk-devel.x86_64

[root@server2 ~]# yum -y install java-11-openjdk
[root@server2 ~]# yum -y install java-11-openjdk-devel

4. 修改java 版本到java11.

[root@server2 ~]#   alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre/bin/java)
   2           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64/bin/java)

Enter to keep the current selection[+], or type selection number: 2
[root@server2 ~]# 
[root@server2 ~]# 
[root@server2 ~]# java -version
openjdk version "11.0.13" 2021-10-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)
[root@server2 ~]# 

5. remove 旧的java 版本

[root@server2 ~]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64
tzdata-java-2021e-1.el7.noarch
javassist-3.16.1-10.el7.noarch
java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64
javamail-1.4.6-8.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
java-11-openjdk-devel-11.0.13.0.8-1.el7_9.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-11-openjdk-headless-11.0.13.0.8-1.el7_9.x86_64
[root@server2 ~]# yum -y remove java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64
           

No comments

Comments feed for this article

Reply

Your email address will not be published.