Java 7 for Ubuntu

Ubuntu announced to discontinue packaging of Sun/Oracle’s Java for Ubuntu, because Oracle changed the licensing.

Please be careful with upgrades on these packages, since it may drop your Java installation on the system, not only the browser plug-in.

I followed these steps to get Oracle Java 7 support on my Ubuntu 10.04 LTS:

  • Downloadjdk-7*-linux-*.tar.gz from Oracle
  • Get privileges: sudo bash
  • Extract the archive: tar -C /usr/lib/jvm -zxf jdk-7*-linux-*.tar.gz
  • Link to generic name java-7-oracle: cd /usr/lib/jvm && ln -snf jdk1.7* java-7-oracle
  • Register Java commands using update-alternatives: register-alternatives.sh
  • If you have a 32-Bit architecture , changed the downloaded .sh-script appropriately, i.e. replace amd64 by i386: sed -i -e 's/amd64/i386/g' register-alternatives.sh
  • Prepare /usr/lib/jvm/.java-7-oracle.jinfo.
  • Mind the name, it begins with a dot.
  • If you have a 32Bit-Linux, change the downloaded .jinfo-file appropriately, i.e. replace amd64 by i386: sed -i -e 's/amd64/i386/g' /usr/lib/jvm/.java-7-oracle.jinfo
  • Switch default Java release: update-java-alternatives --set java-7-oracle

Check the Installation

  • On the command line you can check the Java version by simply calling: java -version
  • In the browser, just follow [testjava.jsp][4].
  • In Firefox you can also see a related Java entry in the [about:plugins][5].

Updates

Because the default Java release is no longer bound to the Ubuntu repositories, you have to take care of updates on your own.

Choose some channel (e.g. Heise Security, Oracle Security Alerts) to watch out for security-related updates of Oracle Java.

An update should be fairly easy, repeat the first steps of the installation described above:

  • Download jdk-7*-linux-*.tar.gz from Oracle
  • Get privileges: sudo bash
  • Extract the archive:
  • Link to generic name java-7-oracle: cd /usr/lib/jvm && ln -snf $(ls -td jdk1.7* | head -1) java-7-oracle

Advantage of the Overhead with Alternatives

The advantage of this method with registration of alternatives in contrast to installing the JDK after the download just at /opt or /usr/local is the integration into the system.

You can immediately start using the standard commands like java, javac, jar and that calls the latest release. You don’t have to redefine your PATH at different locations, searching for the reason, why you are still missing one.