Wednesday, December 18, 2013

Install Java on Linux


How to Install Java on Linux?


I have seen many posts where they explain how to install Java on Linux but none of them had clear instruction(They may be clear for experienced Linux user but not clear for a naive user). This is the reason why this post is coming out. Here I will explain how to install JDK(Oracle) on Linux system and also how to have multiple versions of Java on single linux machine. 

Installation instruction for JDK 7.0 and up is different compared to JDK 6.0 and below. So I will explain them separately. 

Installing JDK7.0 and up:

1) Download JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html (.tar version)
2) Extract it and move it to /usr/lib/jvm(You can move it to any directory you want)
3) sudo gedit /etc/profile, add below lines
JAVA_HOME=/usr/lib/jvm/jdk1.7.0_35
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

4) Check for java_home using -> echo $JAVA_HOME
5) Check for java version using -> java -version

Thats it. This will install java on your linux system. If it shows any problem then restart your system.

Installing JDK6.0 and below:


1) Download JDK from http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u45-oth-JPR
2) Change the directory where you want to install JDk. I am changing to /usr/lib/jvm.
cd /usr/lib/jvm
3) Copy the bin file to /usr/lib/jvm
4) Change the persmission of the  .bin file chmod +x 6u <version>-linux-x64.bin
5) Get the root access(Sudo su).  and then install the jdk using the following command ./jdk-6u35-linux-x64.bin 
6) sudo gedit /etc/profile, add below lines
JAVA_HOME=/usr/lib/jvm/jdk1.6.0_35
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

7) Check for java_home using -> echo $JAVA_HOME
8) Check for java version using -> java -version


Having Multiple version on same machine

Installing multiple version of Java is nothing but doing installing jdk twice with the version that you want and setting up the Path and JAVA_HOME variables to the version that you want to use at that particular time. 

Ex: If you want to use jdk1.7.0_35 then in the   /etc/profile file, add the path to this folder.
and if you want to use jdk1.6.0_35 then in the   /etc/profile file, add the path to this folder.

This will inform your system to take the java version that you are suggesting.

I hope this post will help you in installing Java on Linux machine. Any comment or feedback or your experience will help me to learn more.

P.S: I have tested on Ubuntu and Linux Mint and guess must be working on other linux flavour  as well. 

Tags: Install Java on Linux, Install Java on Ubuntu, Install Java on Linux Mint, multiple version of java on same machine, install JDK 7 on linux, install jdk 6 on linux.

No comments:

Post a Comment