Oracle modified the license for Java in mid April 2019. Long story short, they made it non-free for commercial use. One of the side effects of this license change is the PPA that everyone has come to rely on to get Java into Ubuntu (ppa:webupd8team/java) no longer provides free installation packages for Ubuntu due to the new license.

This normally shouldn't be a problem, because OpenJDK is free, is available for Ubuntu, and is extremely easy to install. So most people running Java on Ubuntu are actually using OpenJDK, not Oracle Java.

However, OpenJDK and Java are not exactly the same! There are some applications written in Java which require Oracle Java, and will not run correctly with OpenJDK.

This post shows how to install Oracle Java 8 in Ubuntu 18.04.

Removing OpenJDK

This isn't necessary for most people, but in my case I wanted to completely purge OpenJDK from my system.

Run the following commands:

dpkg -l | egrep "jdk|jre" sudo apt-get purge openjdk-\*

Downloading Oracle Java JRE

Browse over to https://java.com/en/download/manual.jsp and download the "Linux x64" file.

It is approximately 84 MiB in size, and should have a name similar to jre-8u211-linux-x64.tar.gz.

Installing Oracle Java

Run the following commands:

sudo mkdir -p /opt/java cd /opt/java/ sudo tar zxvf ~/Downloads/jre-8u211-linux-x64.tar.gz sudo update-alternatives --install /usr/bin/java java /opt/java/jre1.8.0_211/bin/java 1
Don't just cut-and-paste, you may need to modify the archive filename and target directory.

To verify the version of Java:

update-alternatives --list java /opt/java/jre1.8.0_211/bin/java java -version java version "1.8.0_211" Java(TM) SE Runtime Environment (build 1.8.0_211-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)

If you didn't purge OpenJDK from your system, you now have multiple versions of Java installed. You may need to run sudo update-alternatives --config java to ensure the version you just installed is the active one.

That should be it. Running "java" will now call the one installed in /opt/java/.

Last modified: 2019-05-08
Stéphane Charette, stephanecharette@gmail.com