1. Home
  2. Linux

How to install Java on Linux

The Java Runtime and Java-based applications aren’t as popular as they once were. Many developers are trying their best to get away from it as a platform. Despite the reputation of the Java runtime, is still heavily used today. It’s on Android, popular web applications are powered by it, video games still run on it, and it’s even used on large-scale Linux servers. If you are a Linux user looking to install Java on Linux you have a two options that you can try.

There’s the OpenJDK project, an open-source implementation of the Java Runtime environment that works on virtually every Linux distribution out there with ease. Along with that, Linux users also can install the official Oracle Java kit, which is much more difficult to get going but offers more modern features and better functionality. In this post, we will be going over how to get both of them set up and running.

Option 1 – Java OpenJDK

Given that Oracle’s Java runtime environment is challenging to set up for average users, Java OpenJDK is a handy tool for Linux.

There are many different versions of OpenJDK. As of now, there’s version 11, and it’s got all of the new patches. However, most Linux distributions carry older releases of OpenJDK in their package archives, and those are installable as well.

Installing Java OpenJDK on Linux is super easy, and you won’t need to do a whole lot of hard work. To get it going, open up a terminal window and follow the instructions that correspond with the Linux distribution that you use.

Ubuntu

Ubuntu 18.10, as well as Ubuntu 18.04 LTS, have the latest release of OpenJDK (11). You can easily install it from the primary software archive by running the following Apt command.

sudo apt install openjdk-11-jdk openjdk-11-jre

Alternatively, if you’re still on Ubuntu 16.04 LTS and need Java, you can get OpenJDK 8. Keep in mind that it’s not as new or as feature-filled as version 11!

sudo apt install openjdk-8-jdk openjdk-8-jre

Debian

Getting OpenJDK working on Debian is quite easy. With that said, please keep in mind that the current release of Debian Stable (9) only carries OpenJDK 8, an out of date release.

sudo apt-get install  openjdk-8-jre openjdk-8-jdk

As mentioned above, Debian 9 Stable has some seriously out of date OpenJDK packages. If you require something much newer, consider updating to Debian 10. Or, check out how you can enable Backports to get newer software.

Arch Linux

Arch Linux has the latest OpenJDK packages (version 11). To install it, you won’t need to resort to the AUR. Instead, it’s quite easy to get it going directly from the “Extra” repo, via Pacman.

sudo pacman -S jre-openjdk jdk-openjdk

Fedora

Fedora Linux carries multiple releases of OpenJDK in their software package archive. With that said, it’s best to run the latest release, as it has the latest features.

To get OpenJDK 11 on Fedora Linux, enter the following DNF command in a terminal window.

sudo dnf install java-11-openjdk

OpenSUSE

Need to get the OpenJDK Runtime environment, as well as the development kit for your OpenSUSE Linux system? You’ll be happy to know that it’s very easy to set up! To get it going, enter the Zypper command below.

sudo zypper install java-11-openjdk

Generic Linux

The source code for  OpenJDK is available to install on all of Linux. If you’re using a Linux-based operating system that doesn’t provide OpenJDK out of the box, head over to the download page and grab the code yourself.

Option 2 – Oracle’s Java Runtime Environment

OpenJDK works in most cases. However, it doesn’t work for 100% of the Java applications on Linux. If you’ve run into some issues using OpenJDK, it’s a great idea just to install the official Oracle version.

Oracle Java for Linux works on a variety of Linux distributions. In this section of the guide, we’ll cover how to get the runtime environment working on all distributions that have packages available.

Ubuntu

Even though Ubuntu Linux is the worlds most popular consumer-facing Linux operating system, Oracle does not have a downloadable DEB package for installation. As a result, users have made a third-party PPA archive that does the installation automatically.

To get the PPA working, open up a terminal and use the add-apt-repository command below.

sudo add-apt-repository ppa:webupd8team/java

Next, run the update command.

sudo apt update

Using the Apt command, install Oracle Java 11.

sudo apt install oracle-java11-installer

Finally, set Java 11 as default.

sudo apt install oracle-java11-set-default

Debian

Need Java on Debian? Thanks to the operating system’s similarity to Ubuntu it’s possible to use a PPA. To get it running, launch a terminal and gain root access.

su

Now that you have Root on Debian, add the Java PPA to your system.

echo "deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main" | tee /etc/apt/sources.list.d/linuxuprising-java.list

Next, enable the software source’s GPG key with apt-key.

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A

Run the update command

apt-get update

Install Java 11 from the software sources using Apt-get.

apt-get install oracle-java11-installer

Finally, set Java 11 as default.

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

Arch Linux

There’s no official Oracle Java runtime package in the Arch AUR. If you absolutely need Java, check the official Linux download page. You’ll be able to download and install a TarGZ release of Java. Otherwise, stick with OpenJDK.

Fedora and OpenSUSE

Oracle distributes an RPM of Java, so you’ll be able to easily install Java on Fedora and OpenSUSE. To get it going, head over to the download page on Oracle.com.

On the page, grab the RPM release of Java. Then, open up a terminal and follow the instructions below to install it on your system.

Fedora

cd ~/Downloads

sudo dnf install jre-8u191-linux-x64.rpm

OpenSUSE

cd ~/Downloads

sudo zypper install jre-8u191-linux-x64.rpm

Generic Linux

Oracle has a TarGZ release of their Java runtime. If you require the official Java JRE, head over to this link, download it, and follow the instructions on the page to get it working.

Leave a comment