Java 8 on Ubuntu 14.04

Getting Java 8 on Ubuntu 14.04 is a topic that is very hotly debated (1, 2, 3, etc, etc) but it looks like this important piece of software won’t officially make it into Ubuntu 14.04 in any time frame that is useful – I’m writing this May 2015, OpenJDK 8 was released March 2014 and it doesn’t look any closer to being included now than it did then.

I have a bit of a love hate relationship with the Ubuntu LTS releases, on the one hand it’s great to have a stable base to work from on the other it’s a real pain when something as important, to me at least, as Java 8 isn’t back ported. Java 8 on Ubuntu 14.04, in my opinion, should be a no brainer.

The problem I actually have is not that any of the software I’m running requires Java 8 it’s the software I’m writing. The machine I’m building is going to act as a Continuous Integration (CI) server running Jenkins. Jenkins will happily run on Java 7 but some of the software I’m working on uses Java 8 and therefore Jenkins needs access to Java 8 in order to compile the code. Anyway, enough waffle on with how I fixed this problem…

Java 8 on Ubuntu 14.04

I should point out that this process will install Oracle Java 8 on your machine rather than OpenJDK 8. From a look and feel point of view everything should be basically the same but from a license point of view it’s different as Oracle Java 8 isn’t open source and requires you to sign your life away accept terms and conditions on the first install.

At a terminal on the target machine running the following commands. The first adds a PPA repository, it gives you some additional information about what you are adding and requests that you confirm the addition. Upon confirmation it updates your repository list and adds the repository key. The second updates your package list and then the third actually installs Java 8.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

One of the benefits of OpenJDK is that you can easily install a headless version that requires minimal graphical libraries. The Oracle Java install is quite good requiring only a few X11 libraries as long as you don’t select any of the suggested packages.

Part way through the first time install of Java 8 on Ubuntu you’ll be presented with the bright pink license acceptance screen:

Configuring oracle-java8-installer
Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX
You MUST agree to the license available in http://java.com/license if you want to use Oracle JDK. <Ok>

Press return and then accept the license agreement on the next screen (assuming you accept it):

Configuring oracle-java8-installer
In order to install this package, you must accept the license terms, the "Oracle Binary Code License Agreement for
the Java SE Platform Products and JavaFX ". Not accepting will cancel the installation.
Do you accept the Oracle Binary Code license terms? <Yes> <No>

Java 8 will then be automatically downloaded and installed. The download is fairly large at around 170MB so be prepared for a wait. Once it’s finished check your Java version:

java -version

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

Environment Variables

Java, unfortunately, often requires environment variables to be set. This can be accomplished quickly and easily using this package:

sudo apt-get install oracle-java8-set-default

And that’s it, a fairly painless way to install Java 8 on Ubuntu. The great thing about this package is it will stay up to date automatically. My thanks go our to the WebUpd8 team for putting together such a great package. They already have Java 9 packages available which I’ll be trying out in due course, for now I think Java 9 is maybe a bit unstable for me though.