About Steve Perkins

Steve Perkins is the author of “Hibernate Search by Example”, and has over fifteen years of experience working with enterprise Java. Steve lives in Atlanta, GA, USA and currently works as a software architect at BetterCloud, where he writes software for the Google cloud ecosystem.

How to install Oracle’s Java on Ubuntu the easy way

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:

  1. Download the desired JDK (Java 6 or 7) from Oracle
  2. Assemble it into a .deb package
  3. Create a local apt repository, containing this package
  4. 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


  • 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.

Related Whitepaper:

Java Application Development on Linux

Linux is the fastest-growing Java development platform because it saves money and time by serving as a platform for both development and deployment. But developers face significant platform-specific challenges when managing and deploying Java applications in a controlled production environment.

This is the hands-on guide to the full Java application development lifecycle on Linux. It demonstrates the platform, tools, and application development by showing realistic, easy-to-follow examples. After a simple command-line application introduces basic tools, this program leads readers through business-logic object analysis, database design, Java servlet UIs, Java Server Pages (JSP) UIs, Swing GUIs, and Standard Widget Toolkit (SWT) GUIs. Scaling up to the enterprise level provides the opportunity to use both the JBoss Application Server and the Apache Geronimo Application Servers, and Enterprise JavaBeans (EJB).

Get it Now!  

Leave a Reply

3 + = seven

Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books