[2 min installs] Java on Ubuntu

Author's avatar
Jan Tovarys
Updated on August 30, 2022

Here is how to install Java on Ubuntu 20.04 in under two minutes:

Step 0 - Check if Java is not already installed

Java is already installed on a lot of machines. To check if Java is installed on your system, run the following command:

 
java --version

If the command java is not recognized, java is not installed.

Step 1 - Update the package list on your system

The first step is to update the package list on your system before proceeding to actual installation:

 
sudo apt update -y

apt update downloads the package lists from the repositories and updates them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.

Step 2 - Install JDK

Install Ubuntu’s default JDK with apt

 
sudo apt install default-jdk

Step 3 - Configure JAVA_HOME on Ubuntu

The JAVA_HOME environment variable simply points to the folder in which Java was installed.

To find out where apt installed Java on Ubuntu, issue the following command and copy the location provided:

 
update-alternatives --config java

With the location of the Java install on the clipboard, open up the server’s environment file with Nano:

 
sudo nano /etc/environment

Paste the JAVA_HOME assignment at the bottom of the file:

 
JAVA_HOME="JAVA_HOME="/lib/jvm/java-11-openjdk-amd64/bin/java"

Then force the Ubuntu terminal to reload the environment configuration file:

 
source /etc/environment

That’s it

Java is now installed on your system. You can check Java version using the following command:

 
java --version
Author's avatar
Article by
Jan Tovarys
Check Uptime, Ping, Ports, SSL and more.
Get Slack, SMS and phone incident alerts.
Easy on-call duty scheduling.
Create free status page on your domain.
Got an article suggestion? Let us know
Next article
[2 min installs] Go on Ubuntu
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.