JSRUN 用代码说话

How to install Oracle JDK 8 on CentOS


java8-centos-example java8-centos-example

In this tutorial, we will show you how to install Oracle JDK 8 On CentOS.

Environment :

  1. CentOS 6.8
  2. Oracle JDK 8u102

This guide should work on Fedora and RedHat.

1. Get Oracle JDK 8

1.1 Visit Oracle JDK download page, look for RPM version.

1.2 Copy the download link of jdk-8u102-linux-x64.rpm and wget it.

$ pwd

$ wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.rpm

2. Install Oracle JDK 8

2.1 Install with yum localinstall.

$ sudo yum localinstall jdk-8u102-linux-x64.rpm

  jdk1.8.0_102.x86_64 2000:1.8.0_102-fcs                                                                                                                                          


2.2 Now the JDK should be installed at /usr/java/jdk1.8.0_102

$ cd /usr/java
$ ls -lsah
total 12K
4.0K drwxr-xr-x   3 root root 4.0K Jul 21 09:58 ./
4.0K drwxr-xr-x. 15 root root 4.0K Jun 22 22:00 ../
   0 lrwxrwxrwx   1 root root   16 Jul 21 09:58 default -> /usr/java/latest/
4.0K drwxr-xr-x   9 root root 4.0K Jul 21 09:58 jdk1.8.0_102/
   0 lrwxrwxrwx   1 root root   22 Jul 21 09:58 latest -> /usr/java/jdk1.8.0_102/

2.3 Verification

$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

2.4 Delete the RPM file

$ rm ~/jdk-8u102-linux-x64.rpm

Done. Oracle JDK 8 is installed on CentOS successfully.

3. JAVA_HOME Environment Variables

This is good practice to set the JAVA_HOME environment variable.

3.1 Edit the .bash_profile, and append the export JAVA_HOME at the end of the file, for example :


# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc

# User specific environment and startup programs

export JAVA_HOME=/usr/java/jdk1.8.0_102/
export JRE_HOME=/usr/java/jdk1.8.0_102/jre


export PATH

3.2 Test the $JAVA_HOME and $PATH

$ source .bash_profile 

$ echo $JRE_HOME

$ echo $JAVA_HOME

$ echo $PATH

4. Multiple JDK installed

If the CentOS has multiple JDK installed, you can use the alternatives command to set the default java

$ sudo alternatives --config java
[sudo] password for mkyong: 

There are 2 programs which provide 'java'.

  Selection    Command
   1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
*+ 2           /usr/java/jdk1.8.0_102/jre/bin/java

Enter to keep the current selection[+], or type selection number:


  1. How to Install Oracle JDK 8 On Debian
  2. How To Install Java on CentOS and Fedora
  3. How to set JAVA environment variables in Linux or CentOS
  4. How to use the ‘alternatives’ command to Install Java 8 on CentOS/RHEL and Fedora
  5. The Difference Between Fedora, Redhat, and CentOS
JSRUN闪电教程系统是国内最先开创的教程维护系统, 所有工程师都可以参与共同维护的闪电教程,让知识的积累变得统一完整、自成体系。 大家可以一起参与进共编,让零散的知识点帮助更多的人。
金额: 0
正在生成二维码, 此过程可能需要15秒钟