Can I install a 32-bit Java in addition to a 64-bit version?

Solution 1:

It's super easy to have multiple versions of Java installed. Somewhat harder (read: tedious) is switching between versions at a whim.

tldr

  1. apt-get one
  2. untar the other
  3. export paths depending which one you want

apt-get one version

Decide which version you'll mostly be using. Or decide which one you want to have automatic updates. Or flip a coin, whatever. You don't even have to use apt-get; just manually maintain both packages on your system (see next heading).

The point is: it's easier to use Ubuntu's package manager to maintain exactly one version of a package like java. You're gonna take care of the rest.

untar the other

Download a jdk tarball. Extract it to /opt.

switch between them

I let the package manager handle my primary install. I export some vars for the other one when I need it. I work on the command line a lot, so it's an okay solution for me. I bother with:

export JAVA_HOME=/opt/jdk
export PATH=$JAVA_HOME/bin:$PATH

Also, I symlink jdk/ -> jdk1.6.0_3/ because I'm lazy and don't like reconfiguring my .bashrc and other scripts every incremental jdk upgrade.

Environment variables you might care about:

JAVA_LIBDIR
JNI_LIBDIR
JAVAJNI_LIBDIR
JVM_ROOT
JAVA_HOME
PATH

Solution 2:

Installation

First, download the latest 32 bit JDK (not JRE) from Sun. At the time this was jdk-6u7-linux-i586.bin for me.

Install java-package:

sudo apt-get install java-package 

Now use java-package to build a .deb package from the binary you downloaded. You have to trick it into building the 32 bit package:

DEB_BUILD_GNU_TYPE=i486-linux-gnu DEB_BUILD_ARCH=i386 fakeroot make-jpkg jdk-6u7-linux-i586.bin 

This should generate a .deb package. For some reason the package name has the _amd64 suffix. Install the package:

sudo dpkg -i sun-j2sdk1.6_1.6.0+update7_amd64.deb 

Use update-alternatives to select the new JDK. It was installed at /usr/lib/j2sdk1.6-sun for me.

sudo update-alternatives --config java 

If you run java -version you should see the correct version:

java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Server VM (build 10.0-b23, mixed mode)

32 bit Eclipse

I had to reinstall the 32 bit version of Eclipse (since SWT contains native code). I also had to delete my ~/.eclipse directory or Eclipse wouldn’t start (this requires reinstalling new versions of any plugins). Finally, add the new JRE in Java->Installed JREs using the install location (/usr/lib/j2sdk1.6-sun) and select it as the default.

ref

Solution 3:

Or you can only install ia32-libs

 apt-get install ia32-libs

unzip the x86 jre

http://javadl.sun.com/webapps/download/AutoDL?BundleId=63983

and add to PATH if you want to.