How to install Java SDK 1.8 on CentOS 7 / RHEL 7
Today we will be looking into the installation of Oracle Java SDK 1.8_u131 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/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz # tar -zxvf jdk-8u*-linux-x64.tar.gz # mv jdk1.8.*/ /usr/
Install Java SDK 8:
Once moved the java to the desired location, Java must setup with the alternatives commands; this will install the Java on your system.
# /usr/sbin/alternatives --install /usr/bin/java java /usr/jdk1.8.*/bin/java 2 # /usr/sbin/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.
TThere are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-22.214.171.124-126.96.36.199.el7_3.x86_64/jre/bin/java) 2 /usr/jdk1.8.0_131/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_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, 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, place your valuable comments below.