一、卸载centos7自带的jdk
通过以下命令查看是否已经安装jdk
yum list installed |grep java
如果安装了则通过以下命令删除
yum -y remove #名称
二、安装jdk
通过以下命令查找能够安装的jdk版本
yum -y list java*
通过以下命令安装jdk1.8
[root@localhost /]# yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 java-1.8.0-openjdk.x86_64.1.1.8.0.252.b09-2.el7_8 将被 安装
--> 正在处理依赖关系 java-1.8.0-openjdk-headless(x86-64) = 1:1.8.0.252.b09-2.el7_8,它被软件包 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 需要
--> 正在处理依赖关系 libjvm.so(SUNWprivate_1.1)(64bit),它被软件包 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 需要
--> 正在处理依赖关系 libjava.so(SUNWprivate_1.1)(64bit),它被软件包 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 需要
--> 正在处理依赖关系 libjvm.so()(64bit),它被软件包 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 需要
--> 正在处理依赖关系 libjava.so()(64bit),它被软件包 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 需要
---> 软件包 java-1.8.0-openjdk-devel.x86_64.1.1.8.0.252.b09-2.el7_8 将被 安装
--> 正在检查事务
---> 软件包 java-1.8.0-openjdk-headless.x86_64.1.1.8.0.252.b09-2.el7_8 将被 安装
--> 正在处理依赖关系 tzdata-java >= 2015d,它被软件包 1:java-1.8.0-openjdk-headless-1.8.0.252.b09-2.el7_8.x86_64 需要
--> 正在检查事务
---> 软件包 tzdata-java.noarch.0.2020a-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=================================================================================================================================================================================================================================================
Package 架构 版本 源 大小
=================================================================================================================================================================================================================================================
正在安装:
java-1.8.0-openjdk x86_64 1:1.8.0.252.b09-2.el7_8 updates 295 k
java-1.8.0-openjdk-devel x86_64 1:1.8.0.252.b09-2.el7_8 updates 9.8 M
为依赖而安装:
java-1.8.0-openjdk-headless x86_64 1:1.8.0.252.b09-2.el7_8 updates 32 M
tzdata-java noarch 2020a-1.el7 updates 188 k
事务概要
=================================================================================================================================================================================================================================================
安装 2 软件包 (+2 依赖软件包)
总下载量:42 M
安装大小:148 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/updates/packages/java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY ] 5.1 MB/s | 5.8 MB 00:00:07 ETA
java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64.rpm 的公钥尚未安装
(1/4): java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64.rpm | 9.8 MB 00:00:06
(2/4): java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64.rpm | 295 kB 00:00:11
(3/4): java-1.8.0-openjdk-headless-1.8.0.252.b09-2.el7_8.x86_64.rpm | 32 MB 00:00:05
(4/4): tzdata-java-2020a-1.el7.noarch.rpm | 188 kB 00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 3.5 MB/s | 42 MB 00:00:12
从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
软件包 : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : tzdata-java-2020a-1.el7.noarch 1/4
正在安装 : 1:java-1.8.0-openjdk-headless-1.8.0.252.b09-2.el7_8.x86_64 2/4
正在安装 : 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 3/4
正在安装 : 1:java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64 4/4
验证中 : tzdata-java-2020a-1.el7.noarch 1/4
验证中 : 1:java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64 2/4
验证中 : 1:java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 3/4
验证中 : 1:java-1.8.0-openjdk-headless-1.8.0.252.b09-2.el7_8.x86_64 4/4
已安装:
java-1.8.0-openjdk.x86_64 1:1.8.0.252.b09-2.el7_8 java-1.8.0-openjdk-devel.x86_64 1:1.8.0.252.b09-2.el7_8
作为依赖被安装:
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.252.b09-2.el7_8 tzdata-java.noarch 0:2020a-1.el7
完毕!
通过以下命令查看jdk是否安装完成
[root@localhost /]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
linux 使用yum命令后,将 OpenSDK 安装到/usr/lib/jvm/ 目录,使用如下命令查看
[root@localhost /]# ls /usr/lib/jvm/
java java-1.8.0 java-1.8.0-openjdk java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 java-openjdk jre jre-1.8.0 jre-1.8.0-openjdk jre-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 jre-openjdk
三、配置环境变量
vi /etc/profile
将下面的三行粘贴到 /etc/profile 中:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
保存关闭后,执行以下命令,让设置立即生效
source /etc/profile
输入以下命令,来确认这三个变量是否设成了我们想要的
echo $JAVA_HOME
echo $CLASSPATH
echo $PATH
[root@localhost /]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
[root@localhost /]# echo $CLASSPATH
.:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/jre/lib/rt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/lib/dt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/lib/tools.jar
[root@localhost /]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/jdk1.8.0_241/bin:/usr/local/java/jdk1.8.0_241/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/bin
wx.jpg
网友评论