CentOS - Install jdk (uninstall openjdk)

Article directory

I. Unloading openjdk

1. View the openjdk version

[nangy@nangy-vm ~]$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

[nangy@nangy-vm ~]$ rpm -qa | grep java
java-1.7.0-openjdk-headless-1.7.0.231-2.6.19.1.el7_6.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2019b-1.el7.noarch
java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
java-1.7.0-openjdk-1.7.0.231-2.6.19.1.el7_6.x86_64

2. Unload openjdk

Use rpm-e -- nodeps for mandatory uninstallation and remove all openjdk s from nodeps

[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.231-2.6.19.1.el7_6.x86_64
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.7.0-openjdk-1.7.0.231-2.6.19.1.el7_6.x86_64

# Verify it.
[nangy@nangy-vm ~]$ java -version
bash: /usr/bin/java: No file or directory

Download jdk1.8

Download official website | JDK 8u211

III. Installation of jdk1.8

Method 1. Manual configuration

1. Preparing jdk files

Download the. tar.gz compression package first

[nangy@nangy-vm ~]$ sudo mkdir /opt/java
[nangy@nangy-vm ~]$ ll /opt/ | grep java
drwxr-xr-x. 2 root root  6 8 Month 2016:47 java
[nangy@nangy-vm ~]$ cd /opt/java/
[nangy@nangy-vm java]$ sudo cp /mnt/hgfs/VMware Shared files/software/jdk-8u211-linux-x64.tar.gz -R /opt/java/
[nangy@nangy-vm java]$ ll
//Total dosage 190424
-rwxr-xr-x. 1 root root 194990602 8 Month 2016:48 jdk-8u211-linux-x64.tar.gz
[nangy@nangy-vm java]$ sudo tar -zxvf jdk-8u211-linux-x64.tar.gz 
[nangy@nangy-vm java]$ cd jdk1.8.0_211/
[nangy@nangy-vm jdk1.8.0_211]$ pwd
/opt/java/jdk1.8.0_211

2. Configuration/etc/profile

[nangy@nangy-vm jdk1.8.0_211]$ sudo vim /etc/profile
  • Add to the tail of / etc/profile
# JAVA_HOME
export JAVA_HOME=/opt/java/jdk1.8.0_211
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

3. Make / etc/profile effective

# Switch to root user
[nangy@nangy-vm jdk1.8.0_211]$ su
[root@nangy-vm jdk1.8.0_211]$ source /etc/profile

[root@nangy-vm jdk1.8.0_211]$ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

Method 2. Installing binary packages

Download the. rpm binary package first

[nangy@nangy-vm download]$ sudo rpm -ivh jdk-8u211-linux-x64.rpm 

[nangy@nangy-vm download]$ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

Off-topic: Installing openJDK

# View the list of available JDK packages
[nangy@nangy-vm ~]$ sudo yum search java | grep -i --color JDK
# Enter the following command yum to install openjdk
[nangy@nangy-vm ~]$ sudo yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64

Keywords: Java sudo JDK RPM

Added by Base on Sun, 06 Oct 2019 13:23:43 +0300