Install Java JDK 8 in CentOS 7/6. 5/6. 4

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

Install Java JDK 8 in CentOS 7/6. 5/6. 4

This tutorial describes how to install and configure the latest Oracle JavaJDK on servers CentOS7, 6.5, and 6.4. Although these steps should also apply to other RPM-based releases, such as RHEL7, 6.x, Scientific Linux6.x, and Fedora.


First, run the update on your server.

yum update

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

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

The output result is as follows:

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

Run the following command to view the installed JAVA version:

java -version

If you have installed Java 1.6 or 1.7, run the following command to uninstall them.

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

When I write this tutorial, the latest JDK version is JDK 8u25. First, download the latest Java version.

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

Because I use 64-bit CentOS 7 server, 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 result 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, run the following command to view the JDK version you have installed.

The output result 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 JDK version has been installed.

Set Global Environment Variables

You can use the following command to easily set the environment variables for JDK installation:

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

Now, run the following command to view the JDK environment variables:

echo $JAVA_HOME

The output result is as follows:

/usr/java/jdk1.8.0_25/

Or

echo $PATH

The output result is as follows:

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

However, the following installation method is not recommended. Because the installation path will disappear after the machine is restarted. To save it, you need to add the installation path to the system configuration file.

Before doing this, we need to create a file named java. sh under/etc/profile. d /.

vi /etc/profile.d/java.sh

Add the following command 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 allow it to run the following commands:

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

Next, enable the changed environment variable to permanently run the following command:

source /etc/profile.d/java.sh

That's right!

-------------------------------------- Split line --------------------------------------

Install JDK 7 In Ubuntu (with Clojure download)

Install JDK 12.04 in Ubuntu

CentOS6.3 install JDK and environment Configuration

Install JDK 8 on Ubuntu 14.04

Install JDK graph analysis in Ubuntu

Install Oracle JDK 14.04 on Ubuntu 1.8 LTS

-------------------------------------- Split line --------------------------------------

What if I don't need to uninstall JDK?

As I mentioned earlier, make sure that you have uninstalled any old JDK version. If you have installed the latest JDK version without uninstalling it, you should tell your system that you have the permission to execute java.

The default JDK installation path is/usr/java/jdk1.8.0 _ 25/. This is where java is executed. We should run the following commands one by one.

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

After all, let's take a look at alternatives.

ls -lA /etc/alternatives/

The output result 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
[...]

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

java -version

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

Click to view Original Text

Translator: penguins in Madagascar want to know the author. Visit the linux community.

Feedback address: mdjsjdqe@foxmail.com

This article is launched by the help translation team's original translation help house.

This article permanently updates the link address:


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.