How to install Java 6 on ubuntu 12.04 / 12.10

Source of Confusion: Many Versions of Java

You will find many methods to install java / jre/ jvm on web and thus it can be very much confusing to a user which method to use. Given there are many implementations of Java available, adds to the confusion. The different implementations of JDK available are:

  1. Java from Oracle (earlier provided by Sun which has been acquired by Oracle
  2. Java available from IBM
  3. OpenJDK
  4. GNU’s JDK

On an ubuntu system, one expects Java to be available as standard debian package installable with apt-get install <package-name>. But on ubuntu packages installed this way is the Open Source Version. If that suits your purpose, you can simply install it using:

$ sudo apt-get install openjdk-6-jdk

However if you wish to install the “Standard Java (earlier Sun Java)”, then it too can be installed either directly from binary distribution or from ubuntu alternate package repository.

Most Common Way:

The simplest way to install java is from a third party repository with

$ sudo add-apt-repository ppa:webupd8team/java

$ sudo apt-get update

$sudo apt-get install oracle-java7-installer


But this works only for Java 7 as Java 6 is not available from ubuntu repositories because of licensing issues. If you download and install Java 6 locally on you machine in your home directory then it is not available to other users on the system and sometimes launching an application which is dependent upon java would be unable to find the java installed in your home directory. Moreover you have to mess with JAVA_HOME, CLASSPATH etc. environment variables. In such a case the best method is to install Java6 manually by following the steps below:

UPDATE: Today I was trying to build android from source and discovered that Java 6 is available now from webupd8team repository. You can simply install oracle / sun java 6 with

$sudo apt-get install oracle-java6-installer

How to install Java 6 Manually

Download the jdk binary from oracles website and follow the steps below:

 $ chmod u+x jdk-6u34-linux-i586.bin
 $ ./jdk-6u34-linux-i586.bin
 $ sudo mkdir -p /usr/lib/jvm
 $ sudo mv jdk1.6.0_34 /usr/lib/jvm/
 $ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_34/bin/java" 1
 $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_34/bin/javac" 1
 $ sudo update-alternatives --install "/usr/lib/mozilla/plugins/" "" "/usr/lib/jvm/jdk1.6.0_34/jre/lib/i386/" 1

Want to install Multiple Versions of Java?

If you already have some other version of java installed on your system say like the Java 7 or say the OpenJDK then you can choose the default java to be used on your system using the update-alternative command. Running the update-alternative shows the list of alternatives for the command and you can choose one of the options listed. As an example if say there are multiple programs fulfilling the same functionality then which one is to be used by a program is not clear. For example say you have installed Aptana Studio IDE on your system which is Eclipse based then to run Aptana it requires jre. If there are multiple versions of jre installed on your system then it is not clear which one should be used to run Aptana. This is where update-alternatives comes into play. For more details check the man page of update-alternatives. To select the version of java to be used by default run the following commands and select the appropriate version.

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

Running the commands above would show a prompt something like this. The details may vary on system to system.

There are 2 choices for the alternative java (providing /usr/bin/java).  
Selection Path Priority Status 
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode 
1 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode  

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


26 thoughts on “How to install Java 6 on ubuntu 12.04 / 12.10

  1. Of special interest to me is the java plugin. Currently we are using Iced Tea, which is not compatible with a web applet required for use in our school. I want to be able to install the Oracle java6 for all users on the system, including and especially the plugin for Mozilla (and Chromium). Will this method also include the plugin?

      • I have only tried the Iced Tea plug-in. This incredibly helpful post made a lot of sense, but my installation is large (~300 users on Ubuntu 12.04LTS and LTSP) and the special applet we use is for managing grades and attendance. It’s a touchy little bugger that requires a particular release of Java6. The Iced Tea plug-in mimics Java6 mostly, except in a few instances where the applet just hangs. Long story… sorry. Was hoping there was some experience with performing this installation on a larger installation of Ubuntu before I dig in and munge things up.

      • I have not tried installing the plugin so sorry I can’t comment on it really. You might want to try it in a VirtualBox VM first before you mess up with your existing installation.

        It would be great if you come up with your results and could post a follow up over here with your results which might help others who come searching over here.

        On Tue, Apr 23, 2013 at 9:37 AM, Thoughts and Ideas In Warped Times

      • I just realized that this method also includes the webstart plugin. So I believe this should work as replacement for your icedtea plugin.

        Hope that helps, Divick

        On Tue, Apr 23, 2013 at 9:37 AM, Thoughts and Ideas In Warped Times

      • I did try your instructions exactly. First, I did not know about the update-alternatives command. Very useful. I followed your instructions exactly (except version… the applet I need requires Java 6, update 31). They all worked without an error.

        The result was that it broke the Java plugin for Firefox. Even after using update-alternatives to reset back to the original Iced Tea, the Oracle testing applet ( reports that no Java is installed.

        This might be a problem with the AMD64/i386 version. My test machine was configured with Ubuntu 12.04LTS 64bit desktop, but I tried your process with the i366 version of the jdk. My LTSP server is AMD64 but the thin clients are i386.

        Also your steps above don’t include installation of the alternative javaws, even though your switching instructions do. It’s not hard to figure out, but just sayin’.

    • In the ubuntu software center you can get the openjdk which i believe includes the ice tea plugin as a dependency

      • Malcom is right. Thanks for pointing me in the right direction buddy. Indeed OpenJDK does come with the IcedTea plugin, and SweetHome3D now launches OK. My configuration = Ubuntu 12.04 32-bit.

  2. I forgot to mention that I altered the steps above to install the JRE, since most of us don’t need the full development kit. It worked OK, but still no joy on the mozilla front.

    • I have not tried and/or tested the plugin installation so sorry I can’t comment on it as of now. If time permits, I will try to do and post my findings. Hope that helps.

      On Wed, Apr 24, 2013 at 1:11 AM, Thoughts and Ideas In Warped Times

      • Divikis, I am curious as to the config of the machine on which you tested the initial installation. I started with a clean (fresh install of 12.04 i386 w/updates) vm last night and did not get the same results. I should have be able to switch between icedtea-6-plugin and However, once I performed your update-alternatives suggestion to install the plug-in, even when switching back, the plug-in broke. The result was that even though update-alternatives selected icedtea-6, Firefox was permanently broken. I am suspect that in the process of installing Java6 there is another symlink that doesn’t get created/updated using the update-alternative tool. Perhaps someone out there with more Firefox/Mozilla power has the answer.

      • I think it was ubuntu 12.04 i386. I will need to check why it doesn’t work but I guess you are on the right track.

        On Wed, Apr 24, 2013 at 10:21 PM, Thoughts and Ideas In Warped Times

  3. It’s time to close the loop on this, and I believe that I have found part of the answer. This is probably only valid on a system that has had the default icedtea-6-plugin/OpenJDK installed.

    First, even though the commands above (which are accurate) add the alternative, they DIDN’T make the new alternative the default application. In the case of Mozilla, you need to do:

    update-alternatives --config

    to select the new alternative Java plug-in.

    Also, the choice to install the i386 jdk version on a amd64 box is a bad one…. I have learned through trial and error. One would think that some downward compatibility exists, but not so. When I committed to install the amd64 version, it worked beautifully! Using update-alternatives to switch between icedtea and the Oracle plugin worked as well.

    Finally, I have not found the solution for installing the alternative for my LTSP thin clients. The thin clients run from an i386 image, but the server is a multiple processor amd64. Will I break java on the server if I install for the thin client?

    Don’t know yet. But I will find out.

    For anyone who is following this discussion (and so this can be found by the search engines), there are no problems with the symlinks. When I switched the installation from icedtea to Oracle Java the symlinks changed correctly. And in case you were wondering they are

    /usr/lib/mozilla/extensions/ links to
    /etc/alternatives/ which links to

    When you switch, the final link in the chain is:
    /usr/lib/jvm/jdk1.6.0_XX/jre/lib/i386/ or
    /usr/lib/jvm/jdk1.6.0_XX/jre/lib/amd64/ depending on your platform. XX is the update version of Java.

    I have been trying to solve an undocumented bug with the eSIS application running under icedtea. The applet is picky, requiring Java6 update 31 (jdk-6u31-linux-i586). This bug causes the browser to hang when notification windows pop-up from the applet. Theoretically, switching to the true Oracle plug-in should fix it.

  4. Pingback: whirr 0.8.2 – A> cannot be used as a key; It is not fully specified | so long, and thanks for all the fish!

  5. Hey there! This post couldn’t be written any better!

    Reading this post reminds me of my old room mate!
    He always kept talking about this. I will forward this
    write-up to him. Fairly certain he will have a good
    read. Thanks for sharing!

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