CentOS 7.9下JDK 1.8安装和配置手册

CentOS 7.9下JDK 1.8安装和配置手册

1. 安装前的准备

1.1 安装环境

1.1.1 操作系统内核版本

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

1.1.2 操作系统发行版本

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

1.2 安装文件

1.2.1 安装文件下载

  • 官网地址:https://www.oracle.com/java/
  • 下载地址:https://www.oracle.com/java/technologies/javase-downloads.html
  • 下载地址(快捷):https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html

1.2.2 安装文件列表

  • jdk-8u301-linux-x64.rpm

2. 安装和配置

2.1 软件安装

2.1.1 安装前的检测

  • 查看运行进程
[root@localhost ~]# rpm -qa | grep jdk
jdk1.8-1.8.0_271-fcs.x86_64

2.1.2 安装JDK

  • 切换至软件目录;
[root@localhost ~]# cd /home/Software/JDK/
[root@localhost JDK]# ls
jdk-8u301-linux-x64.rpm
  • 安装“jdk-8u301-linux-x64.rpm”。
[root@localhost JDK]# sudo yum install -y jdk-8u301-linux-x64.rpm 
Loaded plugins: fastestmirror, langpacks
Examining jdk-8u301-linux-x64.rpm: 2000:jdk1.8-1.8.0_301-fcs.x86_64
Marking jdk-8u301-linux-x64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package jdk1.8.x86_64 2000:1.8.0_301-fcs will be installed
--> Finished Dependency Resolution
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

Dependencies Resolved

==================================================================================================================================================================
 Package                         Arch                            Version                                      Repository                                     Size
==================================================================================================================================================================
Installing:
 jdk1.8                          x86_64                          2000:1.8.0_301-fcs                           /jdk-8u301-linux-x64                          253 M

Transaction Summary
==================================================================================================================================================================
Install  1 Package

Total size: 253 M
Installed size: 253 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), "yum check" output follows:
icedtea-web-1.7.1-2.el7_6.x86_64 has missing requires of java-1.8.0-openjdk
jline-1.0-8.el7.noarch has missing requires of java >= ("0", "1.5", None)
  Installing : 2000:jdk1.8-1.8.0_301-fcs.x86_64                                                                                                               1/1 
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...
  Verifying  : 2000:jdk1.8-1.8.0_301-fcs.x86_64                                                                                                               1/1 

Installed:
  jdk1.8.x86_64 2000:1.8.0_301-fcs                                                                                                                                

Complete!

2.2 软件配置

2.2.1 修改环境变量

  • 配置环境变量;
[root@localhost ~]# vim /etc/profile
unset i
unset -f pathmunge

export JAVA_HOME=/usr/java/jdk1.8.0_301-amd64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  • 环境变量生效。
[root@localhost ~]# source /etc/profile
  • 查看环境变量
[root@localhost ~]# env
JAVA_HOME=/usr/java/jdk1.8.0_301-amd64
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

(特别说明:环境变量位置为随机分布)

3. 启动和验证

3.1 软件启动

暂无。

3.2 软件验证

3.2.1 查看软件版本

[root@localhost ~]# java -version
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)

4. 停止和卸载

4.1 软件停止

暂无。

4.2 软件卸载

  • 检测库文件是否存在
[root@localhost ~]# rpm -qa | grep jdk
jdk-11.0.12-11.0.12-ga.x86_64
  • 依次卸载软件文件
[root@localhost ~]# rpm -e jdk-11.0.12-11.0.12-ga.x86_64 --nodeps

参数选项:

rpm -e jdk 普通删除模式

rpm -e –nodeps 强力删除模式,如果使用上面命令删除时,提示有依赖的其他文件,则 用该命令可以对其进行强力删除。

5. 安装目录和核心文件

5.1 安装目录

[root@localhost ~]# cd /usr/java/jdk1.8.0_301-amd64
[root@localhost jdk1.8.0_301-amd64]# ls
bin        include         jmc.txt  legal  LICENSE  README.html  src.zip                             THIRDPARTYLICENSEREADME.txt
COPYRIGHT  javafx-src.zip  jre      lib    man      release      THIRDPARTYLICENSEREADME-JAVAFX.txt

5.2 执行文件

5.3 配置文件

5.4 日志文件

6. 常见问题

6.1 1#问题

6.2 2#问题

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » CentOS 7.9下JDK 1.8安装和配置手册