How to install Java SDK 1.8 on RHEL 6 / CentOS 6

Java

Today we will be looking into the installation of Oracle Java SDK 1.8_u5 on RHEL / CentOS, Java SDK is the most important base to the developers; this guide will be more useful for them to setup development environment when they especially uses Redhat 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.

### 32 Bit ###

# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-i586.tar.gz

### 64 Bit ###

# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz

Extract and move to the desired location, in my case /usr/

### 32 Bit ###

# tar –zxvf jdk-8u5-linux-i586.tar.gz

### 64 Bit ###

# tar –zxvf jdk-8u5-linux-x64.tar.gz

Move it to /usr

# mv jdk1.8.0_05/ /usr/

Install Java:

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.0_05/bin/java 2
 
# /usr/sbin/alternatives --config java

Select the latest java.

There are 3 programs which provide 'java'.
 
Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
2           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
3           /usr/jdk1.8.0_05/bin/java
 
Enter to keep the current selection[+], or type selection number: 3

Verify the Java:

Once setup the alternatives, verify the java version installed using the following command.

# java –version
 
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Client VM (build 25.5-b02, 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_05
 
# export JRE_HOME=/usr/jdk1.8.0_05/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.

POSTS YOU MAY LIKE -:)

Share This Post

Shares