LinuxJava

How to Install Java and JDK in Linux (Ubuntu)

Step-by-step guide to manually installing the Java JDK on Linux, including download, permissions, and environment variable setup.

25 June 2011 · 2 min read

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

If you want the JDK to be available only for a particular user, install it in their home directory. Otherwise, to make it available for all users, install it in /usr.

Steps

  1. Log in to the shell and navigate to the folder where you want to install the JDK. In this example I am installing it under /usr. The shell commands are shown with # prompts (yours may show $ instead). If you are not logged in as root, prefix commands with sudo.
cd /usr
sudo mkdir java
cd java
  1. Download the latest version of the JDK from the Oracle website. You can also install OpenJDK — the steps are more or less the same, just with a different file name and download source.

Go to the Oracle website and open the Java downloads page. Click JDK and you will be presented with various files to download depending on your platform. If your machine is 32-bit, download the x86 setup. If it is 64-bit, download the x64 setup.

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

The above command will download the JDK binary to the java directory.

  1. Change the file permissions to make it executable 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 create a folder named jdk1.6.0_26 in the java directory. This is your Java home.

Setting Up Environment Variables

To set up the environment variables:

export JAVA_HOME=/usr/java/jdk1.6.0_26
export PATH=$PATH:$JAVA_HOME/bin

This will set your JAVA_HOME. You can test the installation with:

java -version

It will show the Java version installed.