How to install Oracle Java 8 on CentOS 7 / RHEL 7
Today we will be looking into the installation of Oracle Java SDK 1.8_u151 on RHEL / CentOS. Java SDK is the most important base for the developers; this guide will be more useful for them to setup development environment when they especially use RHEL or CentOS.
Download Java SDK
You can either use command line or browser to download the JDK, better to use the browser, the easiest one. Visit the Oracle SDK page to download. If you still want to use the command line, use the below command.
# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz # tar -zxvf jdk-8u*-linux-x64.tar.gz # mv jdk1.8.*/ /usr/
Install Oracle Java 8
Once moved the java to the desired location, you must setup Java with the alternatives commands. Below command will install the Java on your system.
# alternatives --install /usr/bin/java java /usr/jdk1.8.*/bin/java 2 # alternatives --config java
Select the latest Java:
If your system has multiple versions of JAVA installed, then the above command may list you all, like below.
There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-126.96.36.199-1.b12.el7_4.x86_64/jre/bin/java) 2 /usr/jdk1.8.0_151/bin/java Enter to keep the current selection[+], or type selection number: 2
Verify the Java
Once you set up the alternatives. Check the java version installed using the following command.
# java –version
java version "1.8.0_151" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
Setup Environmental Variable
The most important part has come now, it should be set before the installation of any Java-based applications.
# export JAVA_HOME=/usr/jdk1.8.0_* # export JRE_HOME=/usr/jdk1.8.0_*/jre/
Set PATH variable too.
# export PATH=$JAVA_HOME/bin:$PATH
To set it as a permanent, place the above three commands in the “/etc/profile” (All Users) or “~/.bash_profile ” (Single User)
That’s All!. Hope this helped you. Place your valuable comments below.