Ubuntu – install a 32-bit Java in addition to a 64-bit version

11.1032-bit64-bitjava

For normal development I'm using the 64-bit VM which comes when I install the Java development kit (OpenJDK) with the package manager.

But there are some Java applications (containing native libraries, I suppose) which don't work on a 64 bit Java VM. (Looks like SoapUI is such a candidate – in version 4.0.1 and 4.5 beta 1, it fails with a segmentation fault if run in a 64 bit VM.)

I tried to install the i386-version of openjdk-6-jre in addition to the 64-bit one, but this is refused by aptitude (saying that it conflicts with the existing 64-bit version). The same happens if I try to install openjdk-jre-7 in the 32-bit version.

An answer to Can I run a Java 32-bit application on a 64bit system proposed to install ia32-sun-java6-bin, but there is no package with this name (or anything with ia32 and Java).

What could I do here to run SoapUI without switching my whole system Java installation to 32 bit?

Best Answer

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
Related Question