Install Java (OpenJDK) on Ubuntu Linux

To install Java on an Ubuntu Linux system:

  • Make sure that the repository library is up to date.

    sudo apt update
  • Perform a search for the OpenJDK packages that are available.

    sudo apt search openjdk
  • The package list displayed will look like the below. You need to choose one depending on which Java version you want, whether you want the JRE (for running applications) or JDK (for developing them), "normal" (for interactive Java apps) or "headless" (for running on a server with no user interactivity), etc.

    openjdk-13-jdk-headless/focal-updates 13.0.7+5-0ubuntu1~20.04 arm64  OpenJDK Development Kit (JDK) (headless)openjdk-13-jre/focal-updates 13.0.7+5-0ubuntu1~20.04 arm64  OpenJDK Java runtime, using Hotspot JITopenjdk-8-jdk-headless/focal-updates,focal-security 8u312-b07-0ubuntu1~20.04 arm64  OpenJDK Development Kit (JDK) (headless)openjdk-8-jre/focal-updates,focal-security 8u312-b07-0ubuntu1~20.04 arm64  OpenJDK Java runtime, using Hotspot JITopenjdk-8-jre-headless/focal-updates,focal-security 8u312-b07-0ubuntu1~20.04 arm64  OpenJDK Java runtime, using Hotspot JIT (headless)openjdk-8-jre-zero/focal-updates,focal-security 8u312-b07-0ubuntu1~20.04 arm64  Alternative JVM for OpenJDK, using Zero/Shark
  • Once you've chosen a Java package, install it.

    sudo apt install openjdk-8-jre-headless
  • Verify the installation was successful.

    java -version
  • The output should look like this, depending on the package you installed.

    openjdk version "1.8.0_312"OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~20.04-b07)OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)