How to install Java in Ubuntu

The JDK 7 installation is done in below version of Ubuntu.


  •  Download  from here 32bit or 64bit Linux “compressed binary file” – it has a “.tar.gz” file extension i.e. “[java-version]-i586.tar.gz” for 32bit and “[java-version]-x64.tar.gz” for 64bit
  • Once the download is complete, uncompressed the file using following command

sudo tar -xvf jdk-7u25-linux-i586.tar.gz

JDK 7 package is extracted into /jdk1.7.0_25 directory.

  • Now move the JDK 7 directory to /usr/lib

            sudo mkdir -p /usr/lib/jvm

            sudo mv jdk1.7.0_25/ /usr/lib/jvm/jdk1.7.0_25

  • Now run

sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.7.0_25/bin/java” 1

sudo update-alternatives –install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.7.0_25/bin/javac” 1

sudo update-alternatives –install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/jdk1.7.0_25/bin/javaws” 1

  • Run

sudo update-alternatives –config java

You will see output similar one below – choose the number of jdk1.7.0_25

There are 2 choices for the alternative java (providing /usr/bin/java).

 Selection    Path                                           Priority          Status


  0      /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java     1071   auto mode

  1      /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java    1071   manual mode

* 2     /usr/lib/jvm/jdk1.7.0_25/bin/java                       1       manual mode

 Press enter to keep the current choice[*], or type selection number: 2


  • Repeat the above step 5 for below commands:

sudo update-alternatives –config javac

sudo update-alternatives –config javaws

  • Check the version of your new JDK 7 installation:

java -version

java version “1.7.0_25”

Java(TM) SE Runtime Environment (build 1.7.0_25-b15)

Java HotSpot(TM) Server VM (build 23.25-b01, mixed mode)

  • Set JAVA_HOME in Ubuntu.

Open the .bashrc

gedit ~/.bashrc

Now add the following to the end of the file.

export JAVA_HOME=/usr/lib/jvm/java-1.7.0_25

export PATH=$PATH:$JAVA_HOME/bin

NOTE: If /usr/lib/jvm/java does not match the actual JAVA_HOME path in your environment, then set the actual JAVA_HOME, where you have installed Java in your machine.

Now, JDK 7 has been successfully installed on your Ubuntu 🙂


3 thoughts on “How to install Java in Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s