Sunday, November 22, 2026
TR
LinuxOpen Source

Installing Java on Ubuntu 20.04

Installing Java on Ubuntu 20.04
Contents
  1. Installing Java on Ubuntu 20.04
  2. 1. Install OpenJDK 11
  3. 2. Install OpenJDK 8
  4. 3. Install Oracle Java 14
  5. Switching Between Multiple Java Versions

Java is the most popular object-oriented, robust, platform-independent programming language. There are multiple applications that your system needs which require Java. This guide will help you install the stable releases of Java (OpenJDK 11 and OpenJDK 8) or Oracle Java 14 on your Ubuntu 20.04 LTS (Focal Fossa) system. You will also find instructions for switching between multiple installed Java versions.

Installing Java on Ubuntu 20.04

Java 11 is the latest LTS release available for installation. The default Ubuntu package repositories include packages for OpenJDK 11. The default repository also includes the previous stable release packages for OpenJDK 8.

The JDK packages provide the complete Java development libraries, which are useful for development systems. To run any Java application, you need the Java Runtime Environment (JRE).

1. Install OpenJDK 11

Run the following command to install the OpenJDK 11 package on your system.

sudo apt update
sudo apt install openjdk-11-jdk

After the installation is complete, you can verify it by checking the Java version:

java -version

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

OpenJDK 11 is installed. Continue with installing OpenJDK 8.

2. Install OpenJDK 8

Java 8 is the previous stable release and runs most Java-based applications. Run the following command to install the OpenJDK 8 package on your system.

sudo apt update
sudo apt install openjdk-8-jdk

After the installation is complete, you can verify it by checking the Java version:

java -version

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)

When everything is done, you have successfully installed Java (OpenJDK) on your Ubuntu system.

3. Install Oracle Java 14

Oracle Java 14 can be downloaded and installed without a commercial license. You can visit the official download page to download the Debian file to your system. You can also use the following command to download the Debian file from the command line.

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/14.0.1+7/664493ef4a6946b186ff29eb326336a2/jdk-14.0.1_linux-x64_bin.deb"

If the command above does not work or you get a file not found error, please go to the official download page. Check the current version and download it to your system.

After downloading the Debian file, install it on your system with the following command:

sudo dpkg -i jdk-14.0.1_linux-x64_bin.deb

The command above installs Oracle Java 15 on your system. All files will be placed under the /usr/lib/jvm directory. Now set an alternative reference for the newly installed Java on your system.

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.1/bin/java 100

Oracle Java 14 is installed on your system. You can use the next step to switch between multiple Java versions on your system.

Switching Between Multiple Java Versions

Most Unix / Linux based systems allow more than one Java version to be installed on a system. If you have multiple Java versions installed on your system, you can switch the default Java version according to your requirements.

update-alternatives provides an option to maintain symbolic links for default commands. To change the command that runs the default Java version in the terminal:

update-alternatives --config java

This will show a list of all Java binaries installed on your system. Enter a number to select the default Java version and press Enter. 

After the command above runs successfully, run the java -version command again to display the current default Java version.

java -version

java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)

Kerim Koç

Systems and infrastructure engineer. I write about Linux, open source, high availability and security.