Install JDK8 in rpm mode on CentOS7

Install JDK8 in rpm mode on CentOS7

After CentOS 7 is successfully installed, OpenJDK's JRE may have been installed by default, but a complete JDK is required for normal JAVA development. So in order to avoid unnecessary trouble in the future, OpenJDK's JRE is uninstalled here and Oracle's JDK8 is reinstalled

1. Installation Instructions

System environment: CentOS 7

Installation method: rpm

Installation package: jdk-8u131-linux-x64.rpm

2. Check the original installation version of the system

[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. Uninstall the openjdk installed on the system

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

Run the following command as 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. Install 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 is installed by default in /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 June 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. Verify the installation

[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. Configure environment variables

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

Set JAVA_HOME and add it to PATH

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

Run the source command to make the changes take effect. Output JAVA_HOME and PATH to confirm whether the changes are effective.

[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

At this point, the installation of JDK8 on CentOS 7 has been successfully completed. For more articles about installing JDK under Linux, please see the following related links

You may also be interested in:
  • Centos 7 installation of OpenJDK 11 two ways and problem summary
  • Centos installation jdk case explanation
  • Graphical tutorial on installing JDK1.8 under CentOS7.4
  • Introduction to installing and configuring JDK under CentOS system

<<:  Nested display implementation of vue router-view

>>:  Encoding problems and solutions when mysql associates two tables

Recommend

IE conditional comments for XHTML

<br />Conditional comments are a feature uni...

Docker realizes the connection with the same IP network segment

Recently, I solved the problem of Docker and the ...

How to install Docker using scripts under Linux Centos

What is the main function of Docker? At present, ...

Detailed analysis of mysql MDL metadata lock

Preface: When you execute a SQL statement in MySQ...

CSS element hiding principle and display:none and visibility:hidden

1. CSS element hiding <br />In CSS, there ar...

How to reset the root password in mysql8.0.12

After installing the database, if you accidentall...

Using better-scroll component in Vue to realize horizontal scrolling function

About Recently, in the process of learning Vue, I...

33 of the best free English fonts shared

ChunkFive Free Typefamily Cuprum JAH I Free font Y...

Methods and steps for deploying multiple war packages in Tomcat

1 Background JDK1.8-u181 and Tomcat8.5.53 were in...

Detailed examples of converting rows to columns and columns to rows in MySQL

mysql row to column, column to row The sentence i...

Method of realizing automated deployment based on Docker+Jenkins

Use Code Cloud to build a Git code storage wareho...

Summary of situations where MySQL indexes will not be used

Types of Indexes in MySQL Generally, they can be ...

Web design must also first have a comprehensive image positioning of the website

⑴ Content determines form. First enrich the conten...

Example usage of Linux compression file command zip

The ".zip" format is used to compress f...

Tutorial on installing mysql under centos7

Recently, I plan to deploy a cloud disk on my hom...