Install Java with apt on Ubuntu Linux

Install Java with apt on Ubuntu Linux

Java is a set of computer software and specifications developed by James Gosling at Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment.

JRE (Java Runtime Environment)

Refresh your local software package database

sudo apt-get update

Check if Java is already installed

java -version

If Java is not currently installed, you’ll see the following output:

Command 'java' not found, but can be installed with:

apt install default-jre              # version 2:1.11-72, or
apt install openjdk-11-jre-headless  # version 11.0.7+10-3ubuntu1
apt install openjdk-13-jre-headless  # version 13.0.3+3-1ubuntu2
apt install openjdk-14-jre-headless  # version 14.0.1+7-1ubuntu1
apt install openjdk-8-jre-headless   # version 8u252-b09-1ubuntu1

Choose the version you want to install e.g.

apt install openjdk-8-jre-headless

Verify the installation

java -version

You’ll see the following output:

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

JDK (Java Development Kit)

Check if JDK is already installed

javac -version

If JDK is not currently installed, you’ll see the following output:

Command 'javac' not found, but can be installed with:

apt install default-jdk              # version 2:1.11-72, or
apt install openjdk-11-jdk-headless  # version 11.0.7+10-3ubuntu1
apt install openjdk-13-jdk-headless  # version 13.0.3+3-1ubuntu2
apt install openjdk-14-jdk-headless  # version 14.0.1+7-1ubuntu1
apt install ecj                      # version 3.16.0-1
apt install openjdk-8-jdk-headless   # version 8u252-b09-1ubuntu1

Choose the version you want to install e.g.

apt install openjdk-8-jdk-headless

Verify the installation

javac -version

You’ll see the following output:

javac 1.8.0_252