Can I install a 32-bit Java in addition to a 64-bit version?
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?
23 Answers
It's super easy to have multiple versions of Java installed. Somewhat harder (read: tedious) is switching between versions at a whim.
tldr
- apt-get one
- untar the other
- 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:$PATHAlso, 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 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.
1Or you can only install ia32-libs
apt-get install ia32-libsunzip the x86 jre
and add to PATH if you want to.
1