当前位置: 代码迷 >> 综合 >> Cent OS 8安装JDK
  详细解决方案

Cent OS 8安装JDK

热度:7   发布时间:2023-12-16 20:56:39.0

 检验JDK

未安装

[admin@bogon ~]$ java -version
bash: java: 未找到命令...
[admin@bogon ~]$ rpm -qa | grep java
[admin@bogon ~]$ 

已安装

如果有默认的jdk,请使用下面命令卸载

[admin@bogon ~]$ yum -y remove java-1.8.0-openjdk-headless.x86_64

 安装JDK

[admin@bogon ~]$ yum list java*
上次元数据过期检查:0:15:21 前,执行于 2020年12月01日 星期二 15时56分10秒。
可安装的软件包
java-1.8.0-openjdk.x86_64           1:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-accessibility.x86_641:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-demo.x86_64      1:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-devel.x86_64     1:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-headless.x86_64  1:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-javadoc.noarch   1:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-javadoc-zip.noarch1:1.8.0.272.b10-1.el8_2            AppStream
java-1.8.0-openjdk-src.x86_64       1:1.8.0.272.b10-1.el8_2            AppStream
java-11-openjdk.x86_64              1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-demo.x86_64         1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-devel.x86_64        1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-headless.x86_64     1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-javadoc.x86_64      1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-javadoc-zip.x86_64  1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-jmods.x86_64        1:11.0.9.11-0.el8_2                AppStream
java-11-openjdk-src.x86_64          1:11.0.9.11-0.el8_2                AppStream
java-atk-wrapper.x86_64             0.33.2-6.el8                       AppStream
javapackages-filesystem.noarch      5.3.0-1.module_el8.0.0+11+5b8c10bd AppStream
javapackages-tools.noarch           5.3.0-1.module_el8.0.0+11+5b8c10bd AppStream
[admin@bogon ~]$ sudo yum install java-11-openjdk* -y
[sudo] admin 的密码:
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
上次元数据过期检查:0:28:21 前,执行于 2020年12月01日 星期二 16时30分05秒。
依赖关系解决。
================================================================================软件包                      架构   版本                        仓库       大小
================================================================================
安装:java-11-openjdk             x86_64 1:11.0.9.11-0.el8_2         AppStream 251 kjava-11-openjdk-demo        x86_64 1:11.0.9.11-0.el8_2         AppStream 4.3 Mjava-11-openjdk-devel       x86_64 1:11.0.9.11-0.el8_2         AppStream 3.4 Mjava-11-openjdk-headless    x86_64 1:11.0.9.11-0.el8_2         AppStream  40 Mjava-11-openjdk-javadoc     x86_64 1:11.0.9.11-0.el8_2         AppStream  16 Mjava-11-openjdk-javadoc-zip x86_64 1:11.0.9.11-0.el8_2         AppStream  42 Mjava-11-openjdk-jmods       x86_64 1:11.0.9.11-0.el8_2         AppStream 323 Mjava-11-openjdk-src         x86_64 1:11.0.9.11-0.el8_2         AppStream  50 M
安装依赖关系:copy-jdk-configs            noarch 3.7-1.el8                   AppStream  27 kjavapackages-filesystem     noarch 5.3.0-1.module_el8.0.0+11+5b8c10bdAppStream  30 klksctp-tools                x86_64 1.0.18-3.el8                base      100 kttmkfdir                    x86_64 3.0.9-54.el8                AppStream  62 ktzdata-java                 noarch 2020d-1.el8                 AppStream 190 kxorg-x11-fonts-Type1        noarch 7.5-19.el8                  AppStream 522 k
启用模块流:javapackages-runtime               201801                                     事务概要
================================================================================
安装  14 软件包总下载:480 M
安装大小:884 M
下载软件包:
(1/14): copy-jdk-configs-3.7-1.el8.noarch.rpm    29 kB/s |  27 kB     00:00    
(2/14): java-11-openjdk-11.0.9.11-0.el8_2.x86_6  74 kB/s | 251 kB     00:03    
(3/14): java-11-openjdk-demo-11.0.9.11-0.el8_2. 441 kB/s | 4.3 MB     00:10    
(4/14): java-11-openjdk-devel-11.0.9.11-0.el8_2 258 kB/s | 3.4 MB     00:13    
(5/14): java-11-openjdk-javadoc-11.0.9.11-0.el8 263 kB/s |  16 MB     01:02    
(6/14): java-11-openjdk-headless-11.0.9.11-0.el 366 kB/s |  40 MB     01:51    
(7/14): java-11-openjdk-javadoc-zip-11.0.9.11-0 322 kB/s |  42 MB     02:14    
(8/14): javapackages-filesystem-5.3.0-1.module_ 100 kB/s |  30 kB     00:00    
(9/14): ttmkfdir-3.0.9-54.el8.x86_64.rpm        203 kB/s |  62 kB     00:00    
(10/14): tzdata-java-2020d-1.el8.noarch.rpm     315 kB/s | 190 kB     00:00    
(11/14): xorg-x11-fonts-Type1-7.5-19.el8.noarch 249 kB/s | 522 kB     00:02    
(12/14): lksctp-tools-1.0.18-3.el8.x86_64.rpm   567 kB/s | 100 kB     00:00    
(13/14): java-11-openjdk-src-11.0.9.11-0.el8_2. 301 kB/s |  50 MB     02:51    
(14/14): java-11-openjdk-jmods-11.0.9.11-0.el8_ 198 kB/s | 323 MB     27:48    
--------------------------------------------------------------------------------
总计                                            282 kB/s | 480 MB     29:01     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务运行脚本: copy-jdk-configs-3.7-1.el8.noarch                               1/1 运行脚本: java-11-openjdk-headless-1:11.0.9.11-0.el8_2.x86_64             1/1 准备中  :                                                                 1/1 安装    : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.    1/14 安装    : lksctp-tools-1.0.18-3.el8.x86_64                               2/14 运行脚本: lksctp-tools-1.0.18-3.el8.x86_64                               2/14 安装    : tzdata-java-2020d-1.el8.noarch                                 3/14 安装    : ttmkfdir-3.0.9-54.el8.x86_64                                   4/14 安装    : xorg-x11-fonts-Type1-7.5-19.el8.noarch                         5/14 运行脚本: xorg-x11-fonts-Type1-7.5-19.el8.noarch                         5/14 安装    : copy-jdk-configs-3.7-1.el8.noarch                              6/14 安装    : java-11-openjdk-headless-1:11.0.9.11-0.el8_2.x86_64            7/14 运行脚本: java-11-openjdk-headless-1:11.0.9.11-0.el8_2.x86_64            7/14 安装    : java-11-openjdk-1:11.0.9.11-0.el8_2.x86_64                     8/14 运行脚本: java-11-openjdk-1:11.0.9.11-0.el8_2.x86_64                     8/14 安装    : java-11-openjdk-devel-1:11.0.9.11-0.el8_2.x86_64               9/14 运行脚本: java-11-openjdk-devel-1:11.0.9.11-0.el8_2.x86_64               9/14 安装    : java-11-openjdk-jmods-1:11.0.9.11-0.el8_2.x86_64              10/14 安装    : java-11-openjdk-demo-1:11.0.9.11-0.el8_2.x86_64               11/14 安装    : java-11-openjdk-javadoc-1:11.0.9.11-0.el8_2.x86_64            12/14 运行脚本: java-11-openjdk-javadoc-1:11.0.9.11-0.el8_2.x86_64            12/14 安装    : java-11-openjdk-javadoc-zip-1:11.0.9.11-0.el8_2.x86_64        13/14 运行脚本: java-11-openjdk-javadoc-zip-1:11.0.9.11-0.el8_2.x86_64        13/14 安装    : java-11-openjdk-src-1:11.0.9.11-0.el8_2.x86_64                14/14 运行脚本: copy-jdk-configs-3.7-1.el8.noarch                             14/14 运行脚本: java-11-openjdk-1:11.0.9.11-0.el8_2.x86_64                    14/14 运行脚本: java-11-openjdk-devel-1:11.0.9.11-0.el8_2.x86_64              14/14 运行脚本: java-11-openjdk-src-1:11.0.9.11-0.el8_2.x86_64                14/14 验证    : copy-jdk-configs-3.7-1.el8.noarch                              1/14 验证    : java-11-openjdk-1:11.0.9.11-0.el8_2.x86_64                     2/14 验证    : java-11-openjdk-demo-1:11.0.9.11-0.el8_2.x86_64                3/14 验证    : java-11-openjdk-devel-1:11.0.9.11-0.el8_2.x86_64               4/14 验证    : java-11-openjdk-headless-1:11.0.9.11-0.el8_2.x86_64            5/14 验证    : java-11-openjdk-javadoc-1:11.0.9.11-0.el8_2.x86_64             6/14 验证    : java-11-openjdk-javadoc-zip-1:11.0.9.11-0.el8_2.x86_64         7/14 验证    : java-11-openjdk-jmods-1:11.0.9.11-0.el8_2.x86_64               8/14 验证    : java-11-openjdk-src-1:11.0.9.11-0.el8_2.x86_64                 9/14 验证    : javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.   10/14 验证    : ttmkfdir-3.0.9-54.el8.x86_64                                  11/14 验证    : tzdata-java-2020d-1.el8.noarch                                12/14 验证    : xorg-x11-fonts-Type1-7.5-19.el8.noarch                        13/14 验证    : lksctp-tools-1.0.18-3.el8.x86_64                              14/14 
Installed products updated.已安装:copy-jdk-configs-3.7-1.el8.noarch                                             java-11-openjdk-1:11.0.9.11-0.el8_2.x86_64                                    java-11-openjdk-demo-1:11.0.9.11-0.el8_2.x86_64                               java-11-openjdk-devel-1:11.0.9.11-0.el8_2.x86_64                              java-11-openjdk-headless-1:11.0.9.11-0.el8_2.x86_64                           java-11-openjdk-javadoc-1:11.0.9.11-0.el8_2.x86_64                            java-11-openjdk-javadoc-zip-1:11.0.9.11-0.el8_2.x86_64                        java-11-openjdk-jmods-1:11.0.9.11-0.el8_2.x86_64                              java-11-openjdk-src-1:11.0.9.11-0.el8_2.x86_64                                javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch             lksctp-tools-1.0.18-3.el8.x86_64                                              ttmkfdir-3.0.9-54.el8.x86_64                                                  tzdata-java-2020d-1.el8.noarch                                                xorg-x11-fonts-Type1-7.5-19.el8.noarch                                        完毕!
[admin@bogon ~]$ java -version
openjdk version "11.0.9" 2020-10-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.9+11-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11-LTS, mixed mode, sharing)
[admin@bogon ~]$ 

总结

查看列表

yum list java*

安装jdk11

若权限不够则需要增加"sudo"

 yum install java-11-openjdk* -y

查看JDK版本

java -version