How To Install Java On Ubuntu

Install Both Oracle Java and the Open Source Alternative

Three programmers looking at code on a computer screen.
Getty Images

There are plenty of ways to install both the Java JRE(Java Runtime Environment) and the Java JDK(Java Development Kit) on Ubuntu. There's no "right" way, but the two main channels are usually best. You can get them both directly from Oracle, the developer behind Java, or you can get the open source Java implementations straight from Ubuntu's default repositories.

Which one you choose is entirely up to you. In most situations, the open source packages are going to be best. They're easier to install, and they'll receive continual updates along with the rest of your system. That said, there are some situations where you'll require the official Oracle implementation. In those cases, you can get the software you need simply enough on your Ubuntu system.

The difference between the JRE and the JDK is important to keep in mind too. Most people will only ever need the JRE. The Java Runtime Environment is exactly what it sounds like. It's the environment that allows your computer to run programs written in Java. More often than not, when you think about "installing Java," you're thinking about getting the JRE to enable your computer to run Java applications, like Minecraft.

If you plan on developing your own programs using Java, you'll need the Java Development Kit, the JDK. The JDK is a must for Java development, including working with Android, but you won't need it to run Java applications.

Install the Open Source JRE

For most people, this is as far as you need to go. Follow these instructions, and Ubuntu will be able to run Java apps.

  1. Open your web browser, and go to the Ubuntu package database.

    If you'd prefer to just use the default, skip to step 5 and install the default-jre package instead.

  2. Scroll down, and use the search field on the page to look for "openjdk."

    Ubuntu package search
  3. Scroll through the results to find either the latest version of the OpenJDK JRE or the specific version you're looking for. Higher numbers indicate more recent releases.

    Ubuntu OpenJDK search results
  4. Open a terminal window by searching for "Terminal" in your applications or pressing Ctrl+Alt+T on your keyboard.

  5. Type the command to install the version of OpenJDK JRE that you found. It should look like:

    sudo apt install openjdk-14-jre
  6. Press Enter on your keyboard. Then, when asked, press y on your keyboard to install the open source JRE and its dependencies.

    Ubuntu install Java JRE
  7. When the install is complete, you'll have a working Java JRE install on your Ubuntu PC.

Install the Open Source JDK

If you're looking to do some Java or Android development on your Ubuntu PC, but you don't need the official Oracle version of the JDK(most people don't), you can install the open source JDK easily on Ubuntu.

  1. Open your browser and navigate to the Ubuntu package database.

    If you'd rather the system default, skip to step 5 and install default-jdk instead.

  2. Use the search feature on the page to look up "openjdk."

    Ubuntu package search
  3. Scroll until you locate either the latest version of the OpenJDK JDK or the specific version you need for your project. Higher numbered releases are newer.

    Ubuntu OpenJDK search results
  4. Open a terminal window by searching for it in your applications menu or using the Ctrl+Alt+T hotkey.

  5. Run a command similar to the one below with the version of the JDK you found to install the open source JDK.

    sudo apt install openjdk-14-jdk
  6. When prompted, press y to install the JDK and its software dependencies.

    Ubuntu install Java JDK
  7. When the install is complete, you'll have the JDK ready to use on Ubuntu.

Install the Oracle JRE and JDK

Sometimes, you'll need the official version of Java from Oracle. This is usually due to business reasons or company requirements. While you can do this manually with the releases provided directly by Oracle, a PPA is much easier to work with. This guide will use a popular PPA to install the Oracle Java release.

  1. Open a terminal window, either by searching for it in your applications menu or by pressing Ctrl+Alt+T.

  2. Add the PPA to your system with the following to commands. When asked, press Enter to agree to add the PPA.

    sudo add-apt-repository ppa:linuxuprising/java
    sudo apt-get update
  3. Now, install the installer package form the PPA. While the PPA can't directly provide Oracle Java, it can give you an installer that makes setting it up much simpler.

    Ubuntu install Oracle Java
    sudo apt install oracle-java13-installer
  4. When the installer starts, it will ask you to accept the Java license agreement. Do so.

    Ubuntu accept Oracle Java License
  5. Wait for the install to complete. When it does, you can run the command below to ensure that Java installed successfully on your system.

    Ubuntu Oracle Java version
java --version