Installing Java JDK 8 in the CentOS 7/6.5/6.4

Source: Internet
Author: User
Tags java jdk 8 oracle java download

This tutorial describes how to install and configure the latest Oracle JAVAJDK on centos7,6.5, and 6.4 of the servers. Although, these steps should also apply to other RPM-based distributions, such as Rhel7,6.x,scientific linux6.x and Fedora.

First, run the update on your server.

yum update

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

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

The output results are as follows:

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

Enter the following command to view the installed Java version

java -version

If you have previously installed version JAVA1.6 or 1.7, please perform the following command to uninstall them.

yum remove java-1.6.0-openjdkyum remove java-1.7.0-openjdk
JDK Download and install Oracle Java JDK

When I wrote this tutorial, the latest version of the JDK was jdk 8u25. First, we'll download the latest version of the Java version.

To the Oracle Java download page download version that matches the computer schema.

Because I'm using 64bit CentOS 7 server, I'm saying that I downloaded a 64-bit RPM package.

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

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

The output results are 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 command to see the version number of the JDK you installed.

The output results are 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 the JDK has been installed.

Setting Global environment variables

We can easily set the environment variables for your JDK installation using the following command:

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

Now, let's look at the environment variables of the JDK using the following command:

echo $JAVA_HOME

The output results are as follows:

/usr/java/jdk1.8.0_25/

Or

echo $PATH

The output results are as follows:

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

However, we do not recommend the following installation methods. Because the installation path disappears after the machine restarts. In order to save it, you need to add the installation path to the system configuration file.

Before we do it, we're going to create a file called java.sh under /etc/profile.d/ .

vi /etc/profile.d/java.sh

Add the following command to the file:

#!/bin/bashJAVA_HOME=/usr/java/jdk1.8.0_25/PATH=$JAVA_HOME/bin:$PATHexport PATH JAVA_HOMEexport CLASSPATH=.

Save and close the file. In order for it to have execute permissions, run the following command:

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

Next, make the environment variable that you just changed to run the following command permanently:

source /etc/profile.d/java.sh

That's right!

--------------------------------------Split Line--------------------------------------

What if I didn't uninstall the JDK version?

As I mentioned earlier, make sure you uninstall any old JDK version. If you do not have to uninstall the JDK version and install the latest JDK version, you should tell your system where Java has permissions to execute.

The default JDK installation path is/usr/java/jdk1.8.0_25/, which is where Java executes, and we should be running one by one and the following commands.

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

When all is done, let's take a look at alternatives.

ls -lA /etc/alternatives/

The output results are as follows:

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

That's right! Now we use the following command to view the Java version:

java -version

The output results are 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 is complete.

Installing Java JDK 8 in the CentOS 7/6.5/6.4

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.