Installing OpenJDK 8 on Ubuntu

As part of setting up my new Ubuntu notebook I wanted to have Java 8 as the default JDK. Unfortunatly there’s only OpenJDK 7 available as a pre-built package and suggests building it from scratch. It references a blog post that explains the required steps and it’s actually quite easy. Here’s how:

Installing required packages

In preparation of the build, a few depencencies need to be installed. Note that we are installing OpenJDK 7, which is required to bootstrap the build. It will be removed later.

sudo apt-get install git mercurial zip bzip2 unzip tar curl
sudo apt-get install ccache make gcc g++
sudo apt-get install ca-certificates ca-certificates-java
sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev
sudo apt-get install libasound2-dev libcups2-dev libfreetype6-dev
sudo apt-get install build-essential
sudo apt-get install openjdk-7-jdk

Getting the build scripts

A Github repository exists that provides build scripts for different OpenJDK versions. In order to build OpenJDK 8, we clone this repository.

mkdir ~/dev/openjdkathome
cd ~/dev/openjdkathome
git clone

Building OpenJDK 8

Now that we have the build scripts, we can initiate the build by starting the linux build script. The documentation of the script makes a distinction between Java 8 and Java 8 with Lambdas. However, in the actual source of the scripts, no such distinction is made. I assume the documentation is a bit out of date there. The resulting SDK is capable of working with Lambdas, anyway.

XUSE_NEW_BUILD_SYSTEM=true XBUILD=true ./obuildfactory/openjdk8/linux/

After the build has finished (~25 minutes), you can remove the OpenJDK 7:

sudo apt-get remove openjdk-7-jdk
sudo apt-get remove openjdk-7-jre
sudo apt-get remove openjdk-7-jre-headless

Additional details can be found in the Github repository where the build scripts are pulled from.

Installing OpenJDK 8

The build step produces its output in sources/openjdk8/build/linux-x86_64-normal-server-release/images. You’ll find a directory for the Java Runtime Environment and one for the Software Development Kit. Running bin/java -version in the SDK directory reveals the exact version of your build, in my case 8u60-b10.

The previously downloaded OpenJDK 7 was installed to /usr/lib/jvm, so I copied the SDK directory to /usr/lib/jvm/openjdk-1.8.0-jdk8u60-b10. For convenience I also set up a symlink ‘openjdk-8‘ pointingĂ‚ to the previous directory.

sudo mkdir -p /usr/lib/jvm
sudo mv sources/openjdk8/build/linux-x86-64-normal-server-release/images/j2sdk-image /usr/lib/jvm/openjdk-[version]
sudo ln -s /usr/lib/jvm/openjdk-[version] /usr/lib/jvm/openjdk-8

Lastly, the JAVA_HOME environment variable needs to be setup and the $JAVA_HOME/bin directory could be added to the PATH. Environment variables for a user can be defined in ~/.profile:

export JAVA_HOME=/usr/lib/jvm/openjdk-8
export PATH=$PATH:$JAVA_HOME/bin


Building OpenJDK 8 is fast and easy. Be mindful though, if you build your own JDK, of course you’ll need to rebuild it if you want to pull in updates. Your packaging system can’t help you now.

One thought on “Installing OpenJDK 8 on Ubuntu

Leave a Reply

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