How to uninstall OpenJDK and install JDK on Centos7?

How to uninstall OpenJDK then to install JDK on CentOS7? The bellow is the process to uninstall OpenJDK then to install JDK on CentOS.

Here, I use JDK 1.8 as an example.

1. Check JDK version on CentOS

[[email protected] ~]# 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)

2. Use grep Linux command to query the installed JDK package.

[[email protected] ~]# rpm -qa|grep jdk
java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64
copy-jdk-configs-2.2-3.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64
java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64

3. Using rpm command to uninstall openJDK

[[email protected] ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.5.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.131-11.b12.el7.x86_64 java-1.8.0-openjdk-1.8.0.131-11.b12.el7.x86_64 java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.5.el7.x86_64

4. Download the JDK1.8 installation package and install it

Download the Linux rpm installation package from the Oracle web. TheĀ JDK download address.

[[email protected] download]# rpm -ivh jdk-8u162-linux-x64.rpm 
In preparation... ######################################## [100%]
Upgrading/installing...
   1:jdk1.8-2000:1.8.0_162-fcs        ################################# [100%]
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...

5. View the installed JDK version

[[email protected] ~]# java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

When you see the installed JDK version information, it means you have installed the JDK on CentOS.

Leave a Comment