Tuesday 27 February 2018

How to install java in rhel/centos

Step 1

Download the required java version from below java archive link.

for 6

JAVA 6

for 7

JAVA 7

for 8

JAVA 8

Step 2

Extract the package in =to the required directory.

tar -xzf jdk-XUxx-linux-xxx.tar.gz

Step 3

Install the java with alternatives.

go to the java directory that you have extracted.

cd /opt/jdkx.x.x_xx/

install with below command

alternatives --install /usr/bin/java java /opt/jdkx.x_xx/bin/java 2

now select that which you want to be default to work with below command

alternatives --config java

example output

There are 4 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /opt/jdk1.6.0_xx/bin/java
 + 2           /opt/jdk1.7.0_xx/bin/java
   3           /opt/jdk1.8.0_144/bin/java
   4           /opt/jdk1.8.0_xxx/bin/java

Enter to keep the current selection[+], or type selection number: 

In this java has been installed still we need to setup javac and jar command with alternatives.

Step 4

With the following command we can install jar and javac

alternatives --install /usr/bin/jar jar /opt/jdkx.x.x_xx/bin/jar 2

alternatives --install /usr/bin/javac javac /opt/jdkx.x.x_xx/bin/javac 2

alternatives --set jar /opt/jdkx.x.x_xx/bin/jar

alternatives --set javac /opt/jdkx.x.x_xx/bin/javac

Now check the java version with below command

java -version

Step 5

Set JAVA home in to the bash_profile

export JAVA_HOME=/opt/jdkx.x.x_xx

export JRE_HOME=/opt/jdkx.x.x_xx/jre

export PATH=$PATH:/opt/jdkx.x.x_xx/bin:/opt/jdkx.x.x_xx/jre/bin

that's all now you can use java.

No comments:

Post a Comment

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...