Developers on Ubuntu are accustomed to seeing at least two flavors of Java. OpenJDK is an open-source build of the Java runtime and compiler. The Oracle JDK is built upon this, but adds some closed-source components.
๐ java-ubuntu-logo
In theory, OpenJDK is the official reference implementation of Java 7, and should be perfectly fine for all your needs. In practice, it is still known for having issues with common app servers and frameworks. OpenJDK is often fine for end-users, but most Java developers on Ubuntu end up installing the Oracle JDK.
Up until 2011, Canonical distributed the Sun/Oracle JDK in the default Ubuntu apt repository. However, Oracle changed the licensing terms of Java, and this was no longer possible. With the official JDK gone from the Ubuntu repository, developers had to download it directly from Oracle. Installation and configuration became a torturous 18-step process.
There is an easier way, which takes you back to the familiar apt-get, and away from wrestling with sudo update-alternatives. There is a project on GitHub called OAB-Java, which basically consists of a single shell script. With one command, this script will:
- Download the desired JDK (Java 6 or 7) from Oracle
- Assemble it into a .deb package
- Create a local apt repository, containing this package
- Add it as an available repository, so that it works with apt-get, Synaptic, or Update Manager
Installing and running this script is as simple as:
wget https://github.com/flexiondotorg/oab-java6/raw/0.2.7 /oab-java.sh -O oab-java.sh chmod +x oab-java.sh sudo ./oab-java.sh -7
Notes:
- The first line refers to version 0.2.7 of the script. There may be a newer version available when you read this, so you should check the GitHub page for the lastest wget URL.
- The last line is passed a -7 parameter, signifying that we want Java 7 instead of the default Java 6.
- This is the only thing I donโt like about this script. Java 6 is very outdated, and nearing the end of its support cycle. You almost certainly want Java 7, but itโs easy to get the wrong version by forgetting to pass this optional -7 parameter.
After the script has run, the Oracle JDK will be available in your list of apt sources. It can be installed through Synaptic, or in a console session like this:
apt-get install oracle-java7-jdk
Thatโs it! You donโt have to force the Oracle JDK into the available list with update-alternatives, or reload your system PATH. You are simply good to go, just like the days back when Canonical distributed the Sun JDK themselves.
Thank you!
We will contact you soon.
Steve PerkinsMarch 15th, 2014Last Updated: March 15th, 2014

This site uses Akismet to reduce spam. Learn how your comment data is processed.