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

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 our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....

Leave a Reply

Your email address will not be published. Required fields are marked *

*


− three = 2

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close