CentOS7上以rpm方式安装JDK8

(编辑:jimmy 日期: 2024/12/24 浏览:2)

CentOS 7 安装成功后可能已经默认安装了OpenJDK的JRE,但平时进行JAVA开发时需要用完整的JDK,所以为了避免以后不必要的麻烦,在此卸载了OpenJDK的JRE,并重新安装了Oracle的JDK8

1.安装说明

系统环境:CentOS 7

安装方式:rpm

安装包:jdk-8u131-linux-x64.rpm

2.检查系统原安装版本

[hadoop@centos7-1 ~]$ java -version
OpenJDK Version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
[hadoop@centos7-1 ~]$ rpm -qa|grep java
libvirt-java-devel-0.4.9-4.el7.noarch
tzdata-java-2017b-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64
java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64
libvirt-java-0.4.9-4.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64
java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
python-javapackages-3.4.1-11.el7.noarch
[hadoop@centos7-1 ~]$ 

3.卸载系统已安装的openjdk

libvirt-java-devel-0.4.9-4.el7.noarch
libvirt-java-0.4.9-4.el7.noarch
tzdata-java-2017b-1.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64
java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64
java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64

以root身份运行以下命令

[root@centos7-1 hadoop]# rpm -e --nodeps libvirt-java-devel-0.4.9-4.el7.noarch
[root@centos7-1 hadoop]# rpm -e --nodeps libvirt-java-0.4.9-4.el7.noarch
[root@centos7-1 hadoop]# rpm -e --nodeps tzdata-java-2017b-1.el7.noarch
[root@centos7-1 hadoop]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64
[root@centos7-1 hadoop]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64
[root@centos7-1 hadoop]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64
[root@centos7-1 hadoop]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64

4.安装jdk

[root@centos7-1 local]# ll /usr/local/jdk-8u131-linux-x64.rpm 
 -rw-r--r--. 1 root root 169983496 6月 12 23:17 /usr/local/jdk-8u131-linux-x64.rpm
[root@centos7-1 local]# rpm -ivh jdk-8u131-linux-x64.rpm 
 Preparing...             ################################# [100%]
 Updating / installing...
  1:jdk1.8.0_131-2000:1.8.0_131-fcs ################################# [100%]
 Unpacking JAR files...
  tools.jar...
  plugin.jar...
  javaws.jar...
  deploy.jar...
  rt.jar...
  jsse.jar...
  charsets.jar...
  localedata.jar...
[root@centos7-1 local]# 

jdk默认安装到了 /usr/java/ 下面

[root@centos7-1 local]# ll /usr/java/
total 0
lrwxrwxrwx. 1 root root 16 6月 12 23:18 default -> /usr/java/latest
drwxr-xr-x. 9 root root 268 6月 12 23:18 jdk1.8.0_131
lrwxrwxrwx. 1 root root 22 6月 12 23:18 latest -> /usr/java/jdk1.8.0_131
[root@centos7-1 local]# 

5.验证安装

[root@centos7-1 local]# ll /usr/bin/java
lrwxrwxrwx. 1 root root 22 6月 12 23:18 /usr/bin/java -> /etc/alternatives/java
[root@centos7-1 local]# ll /etc/alternatives/java
lrwxrwxrwx. 1 root root 35 6月 12 23:18 /etc/alternatives/java -> /usr/java/jdk1.8.0_131/jre/bin/java
[root@centos7-1 local]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@centos7-1 local]# 

6.配置环境变量

[hadoop@centos7-1 ~]$ whoami
hadoop
[hadoop@centos7-1 ~]$ vi ~/.bashrc

设置JAVA_HOME,并将它加到PATH中

JAVA_HOME=/usr/java/default
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH

运行source命令,使修改生效。输出JAVA_HOME, PATH确认修改是否生效。

[hadoop@centos7-1 ~]$ source ~/.bashrc
[hadoop@centos7-1 ~]$ echo $JAVA_HOME
/usr/java/default
[hadoop@centos7-1 ~]$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/hadoop/.local/bin:/home/hadoop/bin:/usr/java/default/bin

至此,CentOS 7上安装JDK8顺利完毕,更多关于linux下安装JDK的文章请查看下面相关链接

一句话新闻

一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?