In this article, we will have explained the necessary steps to install and configure Java on Ubuntu 20.04 Focal Fossa. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
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.
Install Java on Ubuntu
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install Java on the Ubuntu system.
- Installing OpenJDK 14:
Run the following commands to install the OpenJDK 11 JDK package:
sudo apt install openjdk-14-jdk
Once the installation is complete, you can verify it by checking the Java version:
java -version
- Installing OpenJDK 8:
Run the following commands to install the OpenJDK 8 JDK package:
sudo apt install openjdk-8-jdk
Verify the installation:
java -version
Step 3. JAVA_HOME Environment Variable.
To set the JAVA_HOME variable, first find the Java installation path with update-alternatives:
sudo update-alternatives --config java
For example, the installation paths are as follows:
OpenJDK 14 is located at /usr/lib/jvm/java-14-openjdk-amd64/bin/java
If you found the path of your preferred Java installation, open the /etc/environment file:
nano /etc/environment
JAVA_HOME="/usr/lib/jvm/java-14-openjdk-amd64"
For changes to take effect on your current shell you can either log out and log in or run the following source command:
source /etc/environment
Finally, steps, verify that the JAVA_HOME environment variable was correctly set:
echo $JAVA_HOME
Result:
/usr/lib/jvm/java-14-openjdk-amd64
That’s all you need to do to install Java on Ubuntu 20.04 Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.