How To Install Java 8 & Java 8 SDK on CentOS and Fedora

Install Oracle Java 8

This section of the guide will show you how to install Oracle Java 8 update 60 JRE and JDK (64-bit), the latest release of these packages at the time of this writing.

Note: You must accept the Oracle Binary Code License Agreement for Java SE, which is one of the included steps, before installing Oracle Java.

Install Oracle Java 8 JRE

Note: If you would like to install a different release of Oracle Java 8 JRE, go to the Oracle Java 8 JRE Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm package. Substitute the copied download link in place of the highlighted part of the wget command.

Change to your home directory and download the Oracle Java 8 JRE RPM with these commands:

cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jre-8u60-linux-x64.rpm"

Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):

sudo yum localinstall jre-8u60-linux-x64.rpm

Now Java should be installed at /usr/java/jdk1.8.0_60/jre/bin/java, and linked from /usr/bin/java.

You may delete the archive file that you downloaded earlier:

rm ~/jre-8u60-linux-x64.rpm

Congratulations! You have installed Oracle Java 8 JRE.

Install Oracle Java 8 JDK

Note: If you would like to install a different release of Oracle Java 8 JDK, go to the Oracle Java 8 JDK Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm package. Substitute the copied download link in place of the highlighted part of the wget command.

Change to your home directory and download the Oracle Java 8 JDK RPM with these commands:

cd ~
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.rpm"

Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):

sudo yum localinstall jdk-8u60-linux-x64.rpm

Now Java should be installed at /usr/java/jdk1.8.0_60/jre/bin/java, and linked from /usr/bin/java.

You may delete the archive file that you downloaded earlier:

rm ~/jdk-8u60-linux-x64.rpm

Congratulations! You have installed Oracle Java 8 JDK.

Source : How To Install Java on CentOS and Fedora | DigitalOcean