Installing Java 8

Linux RHEL 7 & CentOS 7

Downloading Latest Java

Note: If your CentOS or RHEL is a fresh minimal installation, maybe you have to install wget utility using yum

# yum -y install wget

Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from shell

# cd /opt/
# 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/8u111-b14/jdk-8u111-linux-x64.tar.gz"
# tar xzfv jdk-8u111-linux-x64.tar.gz

Note: For production servers is highly recomended installing Java Server JRE. The Server JRE includes tools for JVM monitoring and tools commonly required for server applications, but does not include browser integration (the Java plug-in)

# cd /opt/
# 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/8u111-b14/server-jre-8u111-linux-x64.tar.gz"
# tar xzfv server-jre-8u111-linux-x64.tar.gz

Configuring Environment Variables

Most of Java based application’s uses environment variables to work. CentOS and RHEL provides of /etc/profile.d/ directory for customizing environment variables per application

# echo "export JAVA_HOME=/opt/jdk1.8.0_111/" >> /etc/profile.d/java.sh
# echo "export JRE_HOME=/opt/jdk1.8.0_111/jre/" >> /etc/profile.d/java.sh
# echo "export PATH=\$PATH:\$JAVA_HOME/bin/:\$JRE_HOME/bin/" >> /etc/profile.d/java.sh
# source /etc/profile.d/java.sh

Install Java with Alternatives

After setting Environment Variables use Alternatives to install Java

# alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 1
# alternatives --install /usr/bin/jar jar $JAVA_HOME/bin/jar 1
# alternatives --set java $JAVA_HOME/bin/java
# alternatives --set jar $JAVA_HOME/bin/jar

At this point Java 8 has been successfully installed on your system.

Note: If you performed this installation in a Development Server, we also recommend to setup javac commands path using alternatives

# alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 1
# alternatives --set javac $JAVA_HOME/bin/javac

Linux Debian & Ubuntu

Downloading Latest Java

Note: If your Ubuntu or Debian is a fresh minimal installation, maybe you have to install wget utility using apt-get

$ sudo apt-get install wget

Download latest Java SE Development Kit 8 release from its official download page or use following commands to download from shell

$ cd /opt/
$ sudo 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/8u111-b14/jdk-8u111-linux-x64.tar.gz"
$ sudo tar xzfv jdk-8u111-linux-x64.tar.gz

Note: For production servers is highly recomended installing Java Server JRE. The Server JRE includes tools for JVM monitoring and tools commonly required for server applications, but does not include browser integration (the Java plug-in)

$ cd /opt/
$ sudo 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/8u111-b14/server-jre-8u111-linux-x64.tar.gz"
$ sudo tar xzfv server-jre-8u111-linux-x64.tar.gz

Configuring Environment Variables

Most of Java based application’s uses environment variables to work. CentOS provides of /etc/profile.d/ directory for customizing environment variables per application

$ sudo echo "export JAVA_HOME=/opt/jdk1.8.0_111/" >> /etc/profile.d/java.sh
$ sudo echo "export JRE_HOME=/opt/jdk1.8.0_111/jre/" >> /etc/profile.d/java.sh
$ sudo echo "export PATH=\$PATH:\$JAVA_HOME/bin/:\$JRE_HOME/bin/" >> /etc/profile.d/java.sh
$ source /etc/profile.d/java.sh

Install Java with Alternatives

After setting Environment Variables use Alternatives to install Java

$ sudo update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 1
$ sudo update-alternatives --install /usr/bin/jar jar $JAVA_HOME/bin/jar 1
$ sudo update-alternatives --set java $JAVA_HOME/bin/java
$ sudo update-alternatives --set jar $JAVA_HOME/bin/jar

At this point Java 8 has been successfully installed on your system.

Note: If you performed this installation in a Development Server, we also recommend to setup javac and jar commands path using alternatives

$ sudo update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 1
$ sudo update-alternatives --set javac $JAVA_HOME/bin/javac

MacOS X

Downloading Latest Java

Note: If your MacOS is a fresh installation, maybe you have to install wget utility

Firstly, launch Terminal (found in Application/Utilities). Download latest Java SE Development Kit 8 release from its official download page or use following commands to download:

$ cd ~/Downloads/
$ 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/8u111-b14/jdk-8u111-macosx-x64.dmg"

Open downloaded file with:

$ open jdk-8u111-macosx-x64.dmg

This command launch a window that contains a pkg file. Make double click and follow instructions