Install Java JDK 8 in CentOS 7/6.5/6.4

Original Link: http://www.cnblogs.com/cgfree/p/5397890.html

This tutorial describes how to install and CentOS Configure the latest on servers 7, 6.5, and 6.4 Oracle JavaJDK for.Although these steps should also apply to other RPM-based distributions, such as RHEL7, 6.x, Scientific Linux 6.x, and Fedora.

 

First, run the update on your server.

yum update

Then, search your system for any version of the installed JDK components.

rpm -qa | grep -E '^open[jre|jdk]|j[re|dk]'

The output is as follows:

gobject-introspection-1.36.0-4.el7.x86_64
pygobject3-base-3.8.2-4.el7.x86_64

Enter the following command to view the installed version of JAVA

java -version

If you have JAVA1.6 or 1.7 installed before, execute the following commands to uninstall them.

yum remove java-1.6.0-openjdk
yum remove java-1.7.0-openjdk

JDK Download and Install Oracle Java JDK

When I wrote this tutorial, the latest version of JDK was JDK 8u25.First let's download the latest version of Java

reach Oracle Java download page Download the version that matches the computer architecture.

Because I'm using 64bit CentOS 7 server, I said I downloaded a 64-bit rpm package.

Then, go to your download directory and run the following command to install it.

rpm -ivh jdk-8u25-linux-x64.rpm

The output is as follows:

Preparing...                          ################################# [100%]
Updating / installing...
1:jdk1.8.0_25-2000:1.8.0_25-fcs      ################################# [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
jfxrt.jar...

View Java version

Now, use the following commands to see the version number of the JDK you installed.

The output is as follows:

java version "1.8.0_25"
ava(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

As shown above, the latest version of JDK has been installed

Setting global environment variables

We can easily set the environment variables for your JDK installation with the following commands:

export JAVA_HOME=/usr/java/jdk1.8.0_25/
export PATH=$PATH:$JAVA_HOME

Now let's look at the JDK environment variables with the following commands:

echo $JAVA_HOME

The output is as follows:

/usr/java/jdk1.8.0_25/

perhaps

echo $PATH

The output is as follows:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.8.0_25/

However, the next installation method is not recommended.Because the installation path will disappear after the machine restarts.In order to save it, you need to add the installation path to the system's configuration file.

Before we do that, we'll create a file called java.sh under / etc/profile.d/.

vi /etc/profile.d/java.sh

Add the following commands to the file:

#!/bin/bash
JAVA_HOME=/usr/java/jdk1.8.0_25/
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
export CLASSPATH=.

Save and close the file.To give it executable privileges, run the following commands:

chmod +x /etc/profile.d/java.sh

Next, make the environment variable you just changed run the following command permanently and effectively:

source /etc/profile.d/java.sh

You're right!

 

-----------------------------------------------------------------------------------------------

What if I had to uninstall the JDK version?

As I mentioned earlier, make sure you uninstall any older JDK versions.If you have to install the latest version of JDK without uninstalling it, you should tell your system that your java has permission to execute there.

The default JDK installation path is/usr/java/jdk1.8.0_25/, which is where Java executes. We should run one by one, with the following commands.

alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_25/jre/bin/java 20000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.8.0_25/bin/jar 20000
alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_25/bin/javac 20000
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8.0_25/jre/bin/javaws 20000
alternatives --set java /usr/java/jdk1.8.0_25/jre/bin/java
alternatives --set jar /usr/java/jdk1.8.0_25/bin/jar
alternatives --set javac /usr/java/jdk1.8.0_25/bin/javac 
alternatives --set javaws /usr/java/jdk1.8.0_25/jre/bin/javaws

When it's all done, let's look at alternatives.

ls -lA /etc/alternatives/

The output is as follows:

lrwxrwxrwx. 1 root root 29 Dec  2 16:24 jar -> /usr/java/jdk1.8.0_25/bin/jar
lrwxrwxrwx. 1 root root 34 Dec  2 16:24 java -> /usr/java/jdk1.8.0_25/jre/bin/java
lrwxrwxrwx. 1 root root 31 Dec  2 16:24 javac -> /usr/java/jdk1.8.0_25/bin/javac
lrwxrwxrwx. 1 root root 36 Dec  2 16:24 javaws -> /usr/java/jdk1.8.0_25/jre/bin/javaws
[...]

You're right!Now let's look at the java version with the following commands:

java -version

The output is as follows:

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Congratulations!Installation complete.

Reprinted at: https://www.cnblogs.com/cgfree/p/5397890.html

Keywords: Java JDK RPM Oracle

Added by hongco on Mon, 05 Aug 2019 23:25:26 +0300