This blog is subject the DISCLAIMER below.

Tuesday, February 27, 2007

Installing JDK6 On Ubuntu

Ubuntu is a great linux distribution. I have been using it for some time and it has never failed me. I have tried to use JDK6 with it but i didn't find a .deb package neither on sun's website nor ubuntu repositories. Fortunately, there is a way around that.

First, you need to download the JDK binary from here. I have downloaded jdk-6-linux-i586.bin the one suitable for my computer and most of us.

Second, chmod it to make it executable:

chmod 755 ./jdk-6-linux-i586.bin

Third, run the binary you have downloaded using this command:

./jdk-6-linux-i586.bin

then press yes to agree to the licence. After that you will find a new folder called jdk1.6.0

Then, you need to move this folder to use/lib/jvm using this command:

sudo mv jdk1.6.0 /usr/lib/jvm

You will need to enter the root password to do that.

sudo update-alternatives --config java

Selection    Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
*+ 2 /usr/lib/jvm/java-gcj/jre/bin/java

Press enter to keep the default[*], or type selection number:
Those are the JVM's that currenlty exist.

Now we have moved the JDK to the folder where JVM's exists, but we need to enable the system to recognize it really exists

This command will finish all these thing:
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0/jre/bin/java 60 \
--slave /usr/share/man/man1/java.1.gz java.1.gz /usr/lib/jvm/jdk1.6.0/man/man1/java.1

Check the JVM's again:

sudo update-alternatives --config java

There are 3 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
*+ 2 /usr/lib/jvm/java-gcj/jre/bin/java
3 /usr/lib/jvm/jdk1.6.0/jre/bin/java

Press enter to keep the default[*], or type selection number:
Now JDK 1.6 exists but it's not the default.
sudo update-alternatives --config java

There are 3 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
+ 2 /usr/lib/jvm/java-gcj/jre/bin/java
* 3 /usr/lib/jvm/jdk1.6.0/jre/bin/java

Press enter to keep the default[*], or type selection number:
Now, select the one that contains JDK1.6.0, which will be 3 in this case.

You are done.

References:
http://trac.centricware.org/wiki/2007/01/28/21.58

3 comments:

Mohammad Alaggan said...

Just a small tip for the readers
Instead of
chmod 755 ./jdk-6-linux-i586.bin
you can do
chmod +x ./jdk-6-linux-i586.bin
the +x sets to executable, you can also make -x, +r, -r, +w, -w, +rw, -rx, any combination of those. r and w are for read and write.

SoCRaT said...

Also, there is a very easy alternative to both methods by downloading the
JDK6 from Ubuntu's package repos by typing the following in terminal:

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

You're done! If you have multiple versions of Java and want to set one
of them as your default, then you have to check your current version
first using:

java -version

If the default one isn't what you want, then you can simply use this
command:

sudo update-java-alternatives

and select the alternative you want from your installed location, Enjoy :)

Anonymous said...

I am unable to update-alternatives using these instructions. Can I tell me where I am wrong.

Thanks,
SV

root@sundar:/home/sundar# update-alternatives --install /usr/bin/java java /opt/jdk1.5.0_07/bin/java 60 --slave /usr/share/man/man1/java.1.gz java.1.gz /opt/jdk1.5.0_07/man/man1
root@sundar:/home/sundar# sudo update-alternatives --config java There are 4 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
2 /usr/lib/jvm/java-gcj/jre/bin/java
*+ 3 /usr/lib/j2se/1.4/bin/java
4 /usr/local/j2sdk1.4.2_12/bin/java

Press enter to keep the default[*], or type selection number:
root@sundar:/home/sundar# update-alternatives --install /usr/bin/java java /opt/jdk1.5.0_07/bin/java 60 --slave /usr/share/man/man1/java.2.gz java.1.gz /opt/jdk1.5.0_07/man/man1
root@sundar:/home/sundar# sudo update-alternatives --config java There are 4 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
2 /usr/lib/jvm/java-gcj/jre/bin/java
*+ 3 /usr/lib/j2se/1.4/bin/java
4 /usr/local/j2sdk1.4.2_12/bin/java

Press enter to keep the default[*], or type selection number: