Wednesday, February 22, 2012

OpenJDK 7 on Ubuntu 11.10

Since Oracle took over Sun, I've been increasingly wary of tying myself too closely to Java. Their decision to shorten the support cycle for versions of Java not under an Oracle support contract was a bit annoying - it virtually forces a migration from Java 6 to Java 7 if you want continued security updates. We run a mixed Linux / Windows environment - so whilst the Linux vendors will continue to support Java 6, our Windows environment needs to be Java 7. So I decided to prepare to upgrade our Linux environment as well to Java 7.

The first surprise was that OpenJDK 7 on Ubuntu requires OpenJDK 6 to be installed as well (!!), and if you later try to uninstall OpenJDK 6 then it'll uninstall OpenJDK 7 as well:
root@gionta:~# apt-get remove --purge openjdk-6-jre
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libdb5.1-java-gcj libdb-je-java eclipse-platform-data libicu4j-java libdb-java libcommons-compress-java libdb5.1-java libicu4j-4.4-java jarwrapper libcommons-el-java fastjar libjasper-java liblucene2-java
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
default-jdk* default-jre* eclipse* eclipse-jdt* eclipse-pde* eclipse-platform* eclipse-rcp* icedtea-netx* icedtea-plugin* icedtea6-plugin* libaccess-bridge-java* libaccess-bridge-java-jni* openjdk-6-jdk*
openjdk-6-jre* openjdk-7-jdk* openjdk-7-jre* sat4j*
0 upgraded, 0 newly installed, 17 to remove and 0 not upgraded.
After this operation, 204 MB disk space will be freed.
Do you want to continue [Y/n]?

And it leaves Java 6 as the default:
root@gionta:~# java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

Ok, so we're stuck with two versions of Java. Ubuntu at least has a redeeming command (update-java-alternatives) which switches all the alternatives symlinks mess to OpenJDK 7:
root@gionta:/etc/alternatives# update-java-alternatives -l
java-1.6.0-openjdk 1061 /usr/lib/jvm/java-1.6.0-openjdk
java-1.7.0-openjdk-amd64 1051 /usr/lib/jvm/java-1.7.0-openjdk-amd64
root@gionta:/etc/alternatives# update-java-alternatives -s java-1.7.0-openjdk-amd64
update-alternatives: error: no alternatives for
update-java-alternatives: plugin alternative does not exist: /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/
root@gionta:/etc/alternatives# java -version
java version "1.7.0_147-icedtea"
OpenJDK Runtime Environment (IcedTea7 2.0) (7~b147-2.0-0ubuntu0.11.10.1)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

I can hear all the Windows lemmings laughing at us now saying "why do those Linux guys put up with that?". Sometimes I wonder too. Why you can't just "apt-get install openjdk-7-jdk" and expect it to work I will never know.