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:
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:
Then force the Ubuntu terminal to reload the environment configuration file:
Java is now installed on your system. You can check Java version using the following command:
We call you when your
website goes down
Get notified with a radically better
infrastructure monitoring platform.