JDK installation is used for developing java based applications. Also when we install JDK, the associated JRE is also installed which provides the platform over which the java application can run.

In this article, we will show the various ways to install JDK in Linux servers.

a)From archive binaries (.tar.gz): This allows you to install a private version of the JDK for the current user into any location, without affecting other JDK installations.

b)From RPM packages (.rpm): This allows you to perform a systemwide installation of the JDK for all users and requires root access.

  1. Download the JDK package from the link “http://www.oracle.com/technetwork/java/javase/downloads”.
    Just for example, we have downloaded rpm file & tar.gz file for Java Version 1.7.80 & rpm file for Java Version – 1.7.76
[root@localhost Java_Pacakges]# pwd
 /root/Desktop/Java_Pacakges
[root@Server1]# ls -ltr
 jdk-7u80-linux-x64.rpm
 jdk-7u80-linux-x64.tar.gz
 jdk-7u76-linux-x64.rpm

2. First, we will install JDK Version – 1.7.76 from RPM Package using Root user.

[root@localhost Java_Pacakges]# rpm -ivh jdk-7u76-linux-x64.rpm
 Preparing... ########################################### [100%]
 1:jdk ########################################### [100%]
 Unpacking JAR files...
 rt.jar...
 jsse.jar...
 charsets.jar...
 tools.jar...
 localedata.jar...
 jfxrt.jar...
[root@Server1]# java -version
 java version "1.7.0_76"
 Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
 Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
Please note that once the RPM is installed from Root user , the java version will be applicable for all the other users present in the system . Lets check the Java version of other user "james" also which will be the same as for Root user(1.7.76).
[root@Server1]# su - james
 [james@Server1]$ java -version
 java version "1.7.0_76"
 Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
 Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

3. Now let’s install a different Java Version-1.7.80 for “James” user only. Here we will use archive binaries (.tar.gz) file. First, we will untar the file which will derive “jdk1.7.0_80” directory as shown below.

[root@Server1]#cd /root/Desktop/Java_Pacakges/
 [root@Server1]# tar -zxvf jdk-7u80-linux-x64.tar.gz
 [root@Server1]# ls
jdk1.7.0_80

Now copy this directory to James home directory

[root@Server1]# cp -R jdk1.7.0_80 /home/james

4. The next step is to export the environment variables in ~/.bashrc script for “james” user as shown below.
Please note that export is used so that $JAVA_HOME and $PATH are made into the environment variables.

[james@Server1]$ cat ~/.bashrc|tail -2
 export JAVA_HOME=/home/james/jdk1.7.0_80
 export PATH=$JAVA_HOME/bin:$PATH

After re-login to “james” user, the system will read the updated bashrc file and the Java version will be set to 1.7.80 as shown below.

[james@Server1]$ java -version
 java version "1.7.0_80"
 Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
 Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

5. But if we check the Java version of Root user , it will be 1.7.76 only.

[root@Server1]# java -version
 java version "1.7.0_76"
 Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
 Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

6. There is one another way to change the Java version.We will need to create the soft link between /usr/bin/java & /root/Desktop/Java_Pacakges/jdk1.7.0_80/bin/java where the binaries of 1.7.80 are present. Let’s go through it also.
Here we are changing the java version of root user from 1.7.76 to 1.7.80.

[root@Server1]# which java
 /usr/bin/java
 [root@Server1]# cd /usr/bin
 [root@Server1]# ls -ltr java
 lrwxrwxrwx. 1 root root 26 Dec 4 04:01 java -> /usr/java/default/bin/java
[root@Server1]# rm -rf java
 [root@Server1]# ln -s /root/Desktop/Java_Pacakges/jdk1.7.0_80/bin/java java

After re-login to root user, the system will read the updated soft link file and the Java version will be set to 1.7.80 as shown below

[root@Server1]# java -version
 java version "1.7.0_80"
 Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
 Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
 [root@localhost bin]#

In this article, you have learned how to install JDK from RPM package, from archive binaries (.tar.gz) & from creating Soft links.

Now you are good to Go to install JDK packages in your Linux systems.

Please leave your comments and feedback in the comment box if you find it beneficial or in case of any doubts.

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of