ItecSoftware Logo

How to Install Java JDK 7 in Ubuntu

Written by Peter Gilg on - like this:
java jdk 7 install

Chances are you installed Open JDK, which ships as default in the package manager and you’re having compatibility issues with some of the apps requiring Java native Java Development Kit. Not only can mismatch of different vendors cause havoc, but also version issues especially between JDK 6 and JDK 7.

Installation of Oracle Java JDK 7 can turn into a major headache, but it doesn’t have to. Here are the steps for a straight forward Java JDK 7 installation in Ubuntu 12.04 Precise Pangolin.

Install Java JDK 7 in Ubuntu

1 – Download the latest JDK 7 from Oracle’s website and select the tar.gz version. Depending on whether you have a 32bit or 64bit version of Ubuntu, also ensure the correct OS type (i386 or amd64). Make sure you select JDK and NOT JRE or Server JRE.2 – After saving the file in your Downloads directory, extract it using the tar command:

tar -xvf ~/Downloads/jdk-7u25-linux-x64.tar.gz

3 – Create the target location for the JDK files:

sudo mkdir -p /usr/lib/jvm/jdk1.7.0

4 – Move the extracted files in it’s directory structure to the created target directory:

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

5 – Now we need to register the 3 Java executables with the OS:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1 

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1

This completes the core JDK 7 installation. The following two steps integrate java with Firefox.

Firefox Java Extension

6 – Create a Mozilla plugins directory if it doesn’t already exists

mkdir ~/.mozilla/plugins/

7 – Create a symlink to the Java extension inside the mozilla plugins directory. Take note and replace the OS version of your path (i386 or amd64)

ln -s /usr/lib/jvm/jdk1.7.0/jre/lib/amd64/ ~/.mozilla/plugins/

Optional Steps

8 – If you need to set your Java HOME variable, add these two lines to /etc/profile:

export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
export PATH=$PATH:$JAVA_HOME/bin

9 – In order to replace the default open-jdk version (which ships with ubuntu) these steps will show a list of Java versions installed and you can set the default you want to use:

sudo update-alternatives –config java
sudo update-alternatives –config javac
sudo update-alternatives –config javaws


Listed in Linux, Ubuntu, Web Development

Tags: java, JDK 7, Oracle

Leave a Reply