Ubuntu – How to replace OpenJDK 6 with OpenJDK 7

11.10javaopenjdk

Surprisingly (as OpenJDK 7 was released to general availability about 4 months ago) Ubuntu 11.10 still uses OpenJDK 6 instead of 7 by default. How do I best fix this? I'd prefer to remove OpenJDK 6 completely and let OpenJDK 7 to be the default-jdk and default-jre.

I don't want the official Oracle tarballs, I want deb repos – the standard Ubuntu way.

Best Answer

The problem is that the default-jre package depends on OpenJDK 6 and most other packages have their dependencies defined as default-jre | openjdk-6-jre | sun-java6-jre - so until OpenJDK 7 becomes officially supported and will be used as the default version, or until all Java-dependent packages update their dependencies, you'll have to keep OpenJDK 6 around and set the OpenJDK 7 as default using update-java-alternatives. Example for 64-bit system:

$ 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
$ sudo update-java-alternatives -s java-1.7.0-openjdk-amd64

On 32-bit system the directory name will differ, you can find the right name using the -l switch. The second command may spit a lot of errors; either use --jre switch or just ignore errors – the script changes what it can and just ignores the rest.

One could theoretically edit the default-jre package to depend on OpenJDK 7, but be warned that this can cause more harm than good.