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

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.
 

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


eight + 4 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
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.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close