Tuesday, August 9, 2011

Java 7 on Ubuntu 11.04

So after 5+ years, we finally have a new version of Java. In spite of mixed reviews, as a software engineer working a lot on the JVM, I still wanted to take it for a spin. However, being an Ubuntu user, this involves a tad bit of work since there are only RPM and binary packages available at this time.

So until there are official or unofficial .deb packages available, we're going to have to sneak in the raw binaries outselves. The following is how I did this on my 64bit Ubuntu 11.04 system. I take no responsibility in breaking your existing Java installation yada yada, you do this at your own responsibility.

Procedure
Start by downloading the binary.

casper@workstation:~$ wget http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz

Then unpack it.

casper@workstation:~$ tar -xzf jdk-7-linux-x64.tar.gz

Remove packed archive and move/rename the extracted folder into something a little more Ubuntu appropiate.

casper@workstation:~$ sudo rm java-7-sun-1.7.0.tar.gz
casper@workstation:~$ sudo mv jdk1.7.0 /usr/lib/jvm/java-7-sun-1.7.0

Follow the Ubuntu tradition, by symlinking a generic major java version to a concrete minor version.

casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun-1.7.0 /usr/lib/jvm/java-7-sun

Override Ubuntu's standard alternatives mechanism, replacing links to Java 6 with links to Java 7. It would be better to use the update-alternatives tools available in Ubuntu, but I was unable to make this work. If you screw something up here, you may have to uninstall and reinstall your JDK/JRE stuff, in order to revert to a working Java installation.

Delete any existing symlinks.

casper@workstation:~$ sudo rm /etc/alternatives/java
casper@workstation:~$ sudo rm /etc/alternatives/javac
casper@workstation:~$ sudo rm /etc/alternatives/javadoc
casper@workstation:~$ sudo rm /etc/alternatives/javah
casper@workstation:~$ sudo rm /etc/alternatives/javap
casper@workstation:~$ sudo rm /etc/alternatives/javaws
casper@workstation:~$ sudo rm /etc/alternatives/java_vm

Create the new symlinks.

casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/jre/bin/java /etc/alternatives/java
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javac /etc/alternatives/javac
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javadoc /etc/alternatives/javadoc
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javah /etc/alternatives/javah
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javap /etc/alternatives/javap
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/bin/javaws /etc/alternatives/javaws
casper@workstation:~$ sudo ln -s /usr/lib/jvm/java-7-sun/jre/bin/java_vm /etc/alternatives/java_vm

Finally, we may aid various client software in locating where Java in installed, by adding a few environment variables. Do this by editing .bashrc in your home directory.

casper@workstation:~$ gksudo gedit $HOME/.bashrc

Scroll down to the end of the file and add two new lines:

export JDK_HOME=/usr/lib/jvm/java-7-sun
export JAVA_HOME=$JDK_HOME

Restart and that's pretty much it, this worked for me, hope it works for you too. Otherwise, throw me a comment below.

Update: If you are unable to run applets wtihin your browsers, this may be caused by the existing Java Plug-in 1.6 clashing with the new incompatible JRE 1.7 you just installed. To remidy this, you can launch the Java Control Panel and disable the JRE 1.7, making 1.6 the only (and thus default) one.


As you can see below, you still retain Java 1.7, but applets and webstart won't try to use any of this new stuff.


Post a Comment