How to Install Java on Ubuntu 20.04

Install Java on Ubuntu 20.04, Ubuntu 20.10, Linux Mint 21

Java is one of the most popular programming languages used to build different kinds of applications and systems. Java runs on all major operating systems and devices. You can find applications developed in Java on your laptop, phone, and game console.
In this article, you will learn how to install Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using the default apt package manager on Ubuntu 20.04 and Ubuntu 20.10.

Install Default Java JRE on Ubunu 20.04

As always, first, update and upgrade your APT through the following command.

$ sudo apt update

Next, check for Java installation on the system. By default, Ubuntu 20.04 includes the Java 11 JDK. If Java is not installed on your system then use the following command to install the Java JDK 11.

$ sudo apt install default-jre

Now, you can check the installed version using the following command:

$ java -version

You will get the following output:

 java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Installing the Default JDK in Ubuntu

Once JRE installed, you might also need the JDK (Java Development Kit) in order to compile and run a Java-based application. To install the JDK, run the following command.

$ sudo apt install default-jdk

After installation, verify the JDK installation by checking the version as shown.

$ javac -version
javac 11.0.10

Setting JAVA_HOME Environment Variable

The JAVA_HOME environment variable is used by some Java applications to determine the Java installation location.
To set the JAVA_HOME environment variable, first, discover where Java is installed by running the following command:

$ readlink -f /usr/bin/java

You will get the following output:


Then open /etc/environment file using nano text editor:

$ sudo nano /etc/environment

Add the following line at the end of the file, make sure to replace the location of your Java installation path.


Save the file and reload the file to apply the changes to your current session:

$ source /etc/environment

Verify that the environment variable is set:

$ echo $JAVA_HOME

You will get the following output:


Uninstalling Java

You can uninstall Java like any other package installed with apt.
For example, to uninstall the default-jdk package enter:

$ sudo apt remove openjdk-11-jdk


In the above guide, you learned how to install Java on Ubuntu 20.04.
If you have any questions, feel free to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button