How to install Java and JDK in Linux (Ubuntu)

We can install Java either using packages or manually. This post explains how to do it manually.

If you want jdk to be available only for particular user , then do it in his home directory. Otherwise if you want to make it available for all the users its better to do it in /usr directory.

Steps

1) Login to shell and go to folder where you want to install jdk . In this example i am doing it in folder in /usr . The shell commands are shown by # statements , it can be $ for you. It doesn’t matter. If the user with which you are logged in is not root. Then you need to prefix commands with sudo.

# cd /usr

# sudo mkdir java

# cd java

Download the latest version of jdk from oracle website. You can also isntall Open jdk . The steps would be more of less same. Just change would be file name and from where to get it.

Go to Oracle website and open the Java downloads page. Click JDK and you will be presented with various files which you can download depending upon your platform. If your machine is 32 bit you would download x86 setup . If its 64 bit then you will download x64 setup.

My machine is 32 bit so i am downloading setup accordingly.

# sudo wget http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-i586.bin

The above command will downlad the jdk binary to java directory.

Next step is to change the permissions for the file to execute and start the install process

# chmod o+x jdk-6u26-linux-i586.bin

# ./ jdk-6u26-linux-i586.bin

This will complete the install process and will create one folder named jdk1.6.0_26 in the java directory. This is your java home and you are done.

Setting up Java environment and path variables.

To setup the environment variables

# export JAVA_HOME=/usr/java/jdk1.6.0_26

Setting the Java path use the following command

# export PATH = $PATH:$JAVA_HOME/bin

This will setup your JAVA_HOME , we can test our java installation with following command

# java –version

It will show the Java version installed.

1 comment:

Please share your views and comments below.

Thank You.