Install Sun JDK 6 on Ubuntu 11.10


Update 2011-12-20: Following up on comments on the post, I added a section on how to  configure the Java Browser Plugin in manual installation

Update 2011-11-25: I added the information regarding the configuration of the JDK as in my previous post  Configuring Java on Kubuntu 10.10


Since Ubuntu 11.10, there is no longer an official package for the Sun/Oracle JDK. The package sun-java6-jdk is no longer officially available.

Method 1: Install a package provided by a PPA

There is a PPA (Personal Package Archives) made available by Roberto Ferramosca. To add this PPA, run the following command from the command line:

    $ sudo add-apt-repository ppa:ferramroberto/java
    $ sudo apt-get update

You can now install the JDK with the following command:

    $ sudo apt-get install sun-java6-jdk

I you’d like to install the JRE or the Java Plugin along with the JDK, use the following:

sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-plugin sun-java6-fonts

You must now set the Sun JDK as the default. You can see how to achieve this in a previous post Configuring Java on Kubuntu 10.10.

The benefit of this method is that the JDK will be updated when a newer version of the package is made available.

Method 2: Installing the JDK manually

This method consists of downloading the adequate JDK from the Oracle Web site. The file is a bin file, e.g. jdk-6u29-linux-x64.bin

The first step is to create a temporary folder where we’ll download the file.

    $ mkdir -p ~/tmp/jdk-6u29
    $ cd ~/tmp/jdk-6u29

Once downloaded, make the file executable and run it.

    $ chmod +x jdk-6u29-linux-x64.bin
    $ ./jdk-6u29-linux-x64.bin

Now copy the file to the preferred target location, e.g. ~/dev/jdk

    $ mkdir -p ~/dev/jdk
    $ cd ..
    $ mv jdk-6u29 ~/dev/jdk/

Let’s now create a symbolic link so that we can easily update with newer versions in the future.

    $ cd ~/dev/jdk
    $ ln -s jdk-6u29 jdk-6

The next step is to add to the ~/.bashrc the path to our JDK binary files.

    #Use the symbolic link
    export JAVA_HOME="~/dev/jdk/jdk-6"
    export PATH=$PATH:$JAVA_HOME/bin

That’s it.

The benefit of this method is that one can install any version of the JDK (6 or 7). The downside is that one must manually upgrade the JDK.

Manually configuring the browser plugin

To configure the plugin, you need the JRE that comes with the JDK. If you installed the JDK in $JAVA_HOME, the JRE is located in $JAVA_HOME/jre.

Based on some documentation that I found on Oracle Web Site, the solution is simply to create symlinks to the plugin. The plugin can be found in

  • $JAVA_HOME/jre/lib/amd64/libnpjp2.so for 64bit machines
  • $JAVA_HOME/jre/lib/i386/libnpjp2.so for 32bit machines

You can go to http://javatester.org/version.html to check that the plugin works fine.

Configuring the plugin for Firefox

Create a symlink to the plugin

$ sudo ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so /usr/lib/firefox-addons/plugins/libnpjp2.so

This shall do the trick.

Configuring the plugin for Chromium

Create a symlink to the plugin

$ sudo ln -s $JAVA_HOME/jre/lib/amd64/libnpjp2.so /usr/lib/chromium-browser/plugins/libnpjp2.so

With Chromium, it is necessary to enable plugins. You can just launch it from the command line once to enable the plugins with the following command

$ chromium-browser --enable-plugins %U

If you now naviate to chrome://plugins/, you shall see something like:

Java – Version: 1.6.0.30
The next generation Java plug-in for Mozilla browsers.
Disable

About these ads

25 Responses to Install Sun JDK 6 on Ubuntu 11.10

  1. Tushar Kumar says:

    Thanks for this information. Really helped.

  2. vjosh says:

    please give the instruction on how to install jdk 1.6 u 20 1586 bin on ubuntu 11.10

  3. Jay says:

    Thank you for your instruction.

  4. Anna Bell says:

    I have used the manual mathod, how can I get the browser plugin to work?
    And why use the symbolic link and not the real target to your jdk in the .bashrc file?

    • Stephan says:

      Which browser do you use?

      I use the symbolic link because when I will update the jdk version, I don’t want any application that depends on it to be aware of that change, hence the symlink.

    • Stephan says:

      Hi Anna,

      I updated the post to explain how to configure the browser plugin for Firefox and Chromium. Should you still have questions, please shoot them.

      Cheers

      • Anna Bell says:

        Thanks for your time. I have tried the steps you mentioned, but it didn’t work for me (firefox or chromium).
        Btw in my Java_home folder I don’t have a lib that contains my i386 folder. The JRE folder contains a lib and that one contains the i386.
        So the link I used was: $JAVA_HOME/jre/lib/i386 …etc

        I will try to delete my jdk, although it works…even for eclipse, and try it again.

      • Stephan says:

        Indeed, I used the JRE for the plugin. I gotta update my post. Thanks for the feedback.

  5. Anna Bell says:

    It don’t work.

    My JDK is located in here: /usr/lib/jvm/jdk1.6.0_30/
    And the symbolic link is this: /etc/alternatives/java

    In my .bashrc file I’ve done this:
    export JAVA_HOME=”/etc/alternatives/java”
    export PATH=$PATH:$JAVA_HOME/bin

    So when I want to use the plugin for firefox (or chrome), I will type: sudo ln -s /usr/lib/jvm/jdk1.6.0_30/jre/lib/i386/libnpjp2.so /usr/lib/firefox-addons/plugins/libnpjp2.so (and for chrome, I will use the chrome folder of course).

    Eclipse works fine, HelloWorld works also fine ;).
    When I echo the $JAVA_HOME, it will give me the symbolic link (/etc/alternatives/java).
    When I try java -version in the terminal it will give me the java version.

    I am desperate :X

    • Anna Bell says:

      OW sorry didn’t saw your last post, I will w8 for the update :)

      • Stephan says:

        What’s your current problem? I can’t fathom it from your comments, so I can’t provide appropriate guidance :s

    • Anna Bell says:

      Hi Stephan,

      I still have the problem, that I can’t see the java plugin in my browsers (firefox and chrome).
      And if I go to the test site you provided, I need to install some plugins. But that shouldn’t be necessary because I have the JDK and created the symbolic link.

      The text above, is my jdk location and are the steps that I have taken in order to create the symbolic link for my browsers.

      Thanks!

      p.s. sorry for my english ;X

      • Stephan says:

        Hi Anna,

        I had a problem with the plugin not being found because of an improper symlink. Can you check that the symlink is correct?

        In the case of Chrome, the folder is different from that of Chromium and it is also mandatory to enable the plugins.

        In the case of Firefox, I actually did not have to do anything special to get it to work. I can’t fathom any reason but incorrect symlinks.

        Cheers

      • Anna Bell says:

        Omg I finally got it….yeah sorry for my noobness, just made the switch!
        I installed the 32bit jdk version and had a 64bit browser, that will not work. It works with a 64bit jdk if you have a 64bit browser :P.

        Thanks for your spare time

  6. Wow! Thank you so much! Works great! :D

  7. No says:

    Thanks man, this helped a lot and I finally can go on with my work :)

  8. Pingback: Hadoop: Prerequisite for Hadoop Setup in Ubuntu | In Cloud We Trust - 8KMiles

    • michelle says:

      Hi,

      I have set JAVA_HOME and PATH variable as in this discussion but I have this error “ClassNotFound” when I used the “java” command to run my “helloworld.class”. What’s the problem? Hope can help. Thanks.

      • Stephan says:

        Hi,

        As you got the ClassNotFound exception, that means that your Java installation works fine.

        The problem is a runtime problem. The class not found means that the class you are trying to run or use is not in the execution classpath. this classpath shall contain all the classes that are used by your program.

        How do you compile and run your program?

        Cheers

  9. j says:

    thanks much! Still works in Xubuntu 12.04. Your tutorial was very easy to follow

  10. I had difficulty getting this to work for OFBiz.Apache.Org so I wrote a brief description here http://cms.mooreworks.net/cms/open-for-business-ofbizapacheorg.aspx.

  11. Pingback: Install JDK 6 on Ubuntu

  12. Mau says:

    By far, the best tutorial out there. It’s the only one I have been able to setup from an Ubuntu Server. Thanks a lot pal!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 163 other followers

%d bloggers like this: