Installing the 32 bit JDK on Ubuntu AMD64

Few days ago I ran into this problem when trying to run GWT hosted mode browser on the AMD 64 version of Ubuntu 9.0.4.

Here is the problem:

1.GWT Hosted browser doesnt run on 64 bit JAVA, so have JAVA_HOME point to 32-bit JRE.

2.To install a 32 bit jre, run :  sudo apt-get install  ia32-sun-java6-bin

3. This does not solve the problem completely, coz maven and sometime eclipse tries to download tools.jar from sun !

And this tools.jar exists in JDK, what it means is that you have to install the 32 bit JDK on your 64 bit Linux.

No, you dont have any deb package for 32 bit Jdk on 64bit linux, you have to manually download the 32 bit jdk, compile it to a .deb package and isntall it.

In rest of the post I will show you how I have spent half of my day solving this problem.

Follow below steps to install 32 bit JDK for 64 bit linux Ubunutu AMD 64 distro:
1. Download the 32 bit version for linux from sun.java.com, I downloaded the version update 17, and file name is jdk-6u17-linux-i586.bin .
2. We need java-package to create a .deb debian package  from the binary, if you dont have java-package already installed on your machine, download java-package with:
sudo apt-get install java-package

3.Next, create the 32 bit debian package for JDk with the command:
DEB_BUILD_GNU_TYPE=i486-linux-gnu DEB_BUILD_ARCH=i386 fakeroot make-jpkg jdk-6u17-linux-i586.bin

where:

make-jpkg – is the command to create a debian java package,
fakeroot  – run the make-jpkg command as root
make-jpkg generates a .deb package installable on debian base linux distros.
In our case it generates sun-j2sdk1.6_1.6.0+update17_amd64.deb

4. Now is when you can install the 32bit JDK you want with
sudo dpkg -i sun-j2sdk1.6_1.6.0+update17_amd64.deb

5. After this, if you run java from shell, you should be able to see:
amjed@amjed-laptop:/usr/share/man$ java -version
java version “1.6.0_17″
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Server VM (build 14.3-b01, mixed mode)

6. To select a different version, and to see where the new jdk is installed use update-alternatives ( this needs sudo access):

amjed@amjed-laptop:/usr/share/man$ sudo update-alternatives –config java

As you can see, there are 3 alternatives which provide `java’.

Selection    Alternative
———————————————–
1    /usr/lib/jvm/java-6-sun/jre/bin/java
2    /usr/lib/jvm/ia32-java-6-sun/jre/bin/java
*+        3    /usr/lib/j2sdk1.6-sun/bin/java

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

You can anytime switch between the jdk in you machine.

Leave a Comment

Filed under Uncategorized

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 )

Connecting to %s