智慧·快乐·成长——科技造福于人。

centos7 卸载jdk1.7 并用yum安装jdk1.8

1.首先要分别检查包含jdk、java、gcj字样的包,然后删除掉;
[root@localhost java]# rpm -qa | grep jdk
java-1.8.0-openjdk-headless-1.8.0.275.b01-0.el7_9.x86_64
java-1.8.0-openjdk-1.8.0.275.b01-0.el7_9.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
[root@localhost java]# rpm -qa | grep java | xargs rpm -e –nodeps
[root@localhost java]# rpm -qa | grep jdk
copy-jdk-configs-3.3-10.el7_5.noarch
yum删除:
[root@localhost java]# yum -y remove copy-jdk-configs.noarch
已加载插件:fastestmirror, langpacks
正在解决依赖关系
……
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
** 发现 2 个已存在的 RPM 数据库问题, ‘yum check’ 输出如下:
tagsoup-1.2.1-8.el7.noarch 有缺少的需求 jpackage-utils
tagsoup-1.2.1-8.el7.noarch 有缺少的需求 jpackage-utils >= (‘0’, ‘1.6’, None)
正在删除 : copy-jdk-configs-3.3-10.el7_5.noarch 1/1
验证中 : copy-jdk-configs-3.3-10.el7_5.noarch 1/1

删除:
copy-jdk-configs.noarch 0:3.3-10.el7_5

完毕!
[root@localhost java]# cd /

2.分别执行三个命令,检查,确认无残留:
[root@localhost /]# rpm -qa | grep gcj
[root@localhost /]# rpm -qa | grep java
[root@localhost /]# rpm -qa | grep jdk

3.vi /etc/profile 删掉所有与JAVA_HOME有关的旧的jdk环境变量,包括path和classpath(只删和java有关的,保险起见,可以先备份一下)。
[root@localhost /]# vi /etc/profile
生效一下环境变量:
[root@localhost /]# source /etc/profile
确认没有残留:
[root@localhost /]# java -version
bash: java: 未找到命令…

4.列出yum源所有的java包,找到1.8的包前缀是java-1.8.0-openjdk:
[root@localhost /]# yum list java*
可安装的软件包
……
java-1.8.0-openjdk.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-src.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.275.b01-0.el7_9 updates
……

5.然后检查该1.8jdk前缀对应的包:
[root@localhost /]# yum list java-1.8*
…….
可安装的软件包
java-1.8.0-openjdk.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-src.i686 1:1.8.0.275.b01-0.el7_9 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.275.b01-0.el7_9 updates

6.开始执行安装:
[root@localhost /]# yum install java-1.8.0-openjdk* -y
……

依赖关系解决

========================================================================================================================
Package 架构 版本 源 大小
========================================================================================================================
正在安装:
java-1.8.0-openjdk x86_64 1:1.8.0.275.b01-0.el7_9 updates 304 k
java-1.8.0-openjdk-accessibility x86_64 1:1.8.0.275.b01-0.el7_9 updates 89 k
java-1.8.0-openjdk-demo x86_64 1:1.8.0.275.b01-0.el7_9 updates 2.0 M
java-1.8.0-openjdk-devel x86_64 1:1.8.0.275.b01-0.el7_9 updates 9.8 M
java-1.8.0-openjdk-headless x86_64 1:1.8.0.275.b01-0.el7_9 updates 33 M
java-1.8.0-openjdk-javadoc noarch 1:1.8.0.275.b01-0.el7_9 updates 15 M
java-1.8.0-openjdk-javadoc-zip noarch 1:1.8.0.275.b01-0.el7_9 updates 42 M
java-1.8.0-openjdk-src x86_64 1:1.8.0.275.b01-0.el7_9 updates 46 M
为依赖而安装:
copy-jdk-configs noarch 3.3-10.el7_5 base 21 k
java-atk-wrapper x86_64 0.30.4-5.el7 base 71 k
javapackages-tools noarch 3.4.1-11.el7 base 73 k
python-javapackages noarch 3.4.1-11.el7 base 31 k
tzdata-java noarch 2020d-2.el7 updates 189 k

事务概要
========================================================================================================================
安装 8 软件包 (+5 依赖软件包)

总下载量:148 M
安装大小:521 M
Downloading packages:
(1/13): java-1.8.0-openjdk-accessibility-1.8.0.275.b01-0.el7_9.x86_64.rpm | 89 kB 00:00:00.
……
————————————————————————————————————————
总计 5.5 MB/s | 148 MB 00:00:26
……

已安装:
java-1.8.0-openjdk.x86_64 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.275.b01-0.el7_9
java-1.8.0-openjdk-src.x86_64 1:1.8.0.275.b01-0.el7_9

作为依赖被安装:
copy-jdk-configs.noarch 0:3.3-10.el7_5 java-atk-wrapper.x86_64 0:0.30.4-5.el7
javapackages-tools.noarch 0:3.4.1-11.el7 python-javapackages.noarch 0:3.4.1-11.el7
tzdata-java.noarch 0:2020d-2.el7

完毕!

7.检查安装是否成功:
[root@localhost /]# java -version
openjdk version “1.8.0_275”
OpenJDK Runtime Environment (build 1.8.0_275-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)

8.总结:使用yum安装无需手动配置环境变量。


转载请注明:转自《centos7 卸载jdk1.7 并用yum安装jdk1.8

赞赏

微信赞赏支付宝赞赏

上一篇

相关文章

在线留言

你必须 登录后 才能留言!