How to install Oracle JDK 8 on CentOS


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"

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

About the Author

author image
Founder of, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


6 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
6 Comment authors
rajendra kumar manthanCyril AntonySrikanth JeevanandanJigneshLukas Fülling Recent comment authors
newest oldest most voted
Lukas Fülling
Lukas Fülling

This no longer works. :c

Srikanth Jeevanandan
Srikanth Jeevanandan

I had to download Java from :

other than that , Works like a charm. Thanks!

rajendra kumar manthan
rajendra kumar manthan

This works perfect.Thanks


Thanks a lot ! It helped me for installation of java 8 on centos.

Lee Namkyu
Lee Namkyu

Thanks for this article.

Cyril Antony
Cyril Antony

i am getting error ‘ Package jdk-8u151-linux-x64.rpm is not signed’ at
Step : sudo yum localinstall jdk-8u102-linux-x64.rpm