How to install sun jdk on Ubuntu and Linux

sun jdk ubuntu linuxI was building an android source code on Ubuntu and got the following error during build process.

Java: CtsVerifier
(out/target/common/obj/APPS/CtsVerifier_intermediates/classes)
cts/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java:
191:
onCreateDialog(int,android.os.Bundle) in android.app.Activity
cannot implement onCreateDialog(int,android.os.Bundle)
in com.android.cts.verifier.PassFailButtons.PassFailActivity;
attempting to assign weaker access privileges;
was public private static

I searched many forums and found that the reason the error coming because I have installed open jdk on Ubuntu 11.10 and to fix this issue I need to install the sun jdk(1.6), so I tried aptitude search for sun jdk in Ubuntu but no such package was present in the repository.

I found two ways to fix this issue. One is specific Ubuntu(easy and simple) and other is applicable for all other Linux operating systems including Ubuntu as well.

Installing Sun Jdk on Ubuntu

Add following repository

sudo add-apt-repository ppa:ferramroberto/java

Install sun jdk 1.6

sudo apt-get update
sudo apt-get install sun-java6-jdk

Install sun jre 1.6

sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin

If you have already installed openJdk then you have to choose default java from preference, execute following command.
sudo update-alternatives --config javac

Done!

Installing sun jdk on Linux or Ubuntu

You will need to install jdk 6 if you are building android source code. I am mentioning steps to install jdk 7 and jdk 6 separately, most of the steps similar except the extracting the tar or bin file.

Installing jdk 7 on Linux/Ubuntu

Download the jdk 7 tar from here.

Extract the tar

tar -xvzf jdk-7u1-linux-i586.tar.gz

Move extracted folder to this location

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

Make new directory named jvm if its not present in /usr/lib/ already

Inform Linux/ubuntu that new java source is available

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

Choose default java(jdk 1.7) on ubuntu/linux

sudo update-alternatives --config javac
sudo update-alternatives --config java

Installing jdk 6 on Linux/Ubuntu

Download the jdk 6 bin from here.

Extract the bin

chmod +x jdk-6u29-linux-i586.bin
./jdk-6u29-linux-i586.bin

Move extracted folder to this location

sudo mv jdk1.6.0_29 /usr/lib/jvm/

Inform Linux/ubuntu that new java source is available

sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_29/bin/javac 1
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_29/bin/java 1

Choose default java(jdk 1.6) on ubuntu/linux

sudo update-alternatives --config javac
sudo update-alternatives --config java

Please leave the comment if you get any difficulties to install sun jdk after following these steps.


Sameer is a Internet technology Blogger from India. He is currently working in Mobile domain. He love to explore latest technology trends in mobile application development and Internet.

7 Responses to “How to install sun jdk on Ubuntu and Linux”

  1. Aks says:

    Hi, Sameer,

    i liked your post here and got the result for it.

    kindly let me know how to update or remove the old java version from sun java .1.6 installed version to sun 1.7 version in ubuntu linux 11.10

    can we do this installation task through synaptic package manager?

    looking forward for your comments !

    • Sameer says:

      Thanks Aks! If you have installed the jdk 1.6 from synaptic earlier try to remove it from synaptic manager. You can keep both the version of jdk 1.6 and 1.7 too, just follow my steps to install jdk 1.7 and in the end execute these commands.
      sudo update-alternatives --config javac
      sudo update-alternatives --config java

      It will ask you to choose default java and javac versions, choose 1.7 as you want jdk 1.7. Hope this will help to solve your issue :)
      – Sameer

      • aks says:

        sameer, i think you have missed one command for unpacking the jdk 1.6 on ubuntu

        i.e.
        chmod +x jdk-6u29-linux-x64.bin

        and then follow the process given as

        ./jdk-6u29-linux-i586.bin

        let me know whether it is required or not ?

  2. Victor says:

    Thanks for this, really helped me

  3. Luis Eduardo says:

    Great post Sameer! I have been looking over the internet for someone who knew how to do this.

    Actually I tried to symlink those files with “sudo ln -s jdk1.6.0_29/bin/javac /usr/bin/javac” and “sudo ln -s jdk1.6.0_29/bin/java /usr/bin/java” but i found it a little “hardcoded”.
    This way is much better.

    Thanks for this usefull information

Leave a Reply

© 2017 MobiTechie. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie