Java is one of the most widely used programming languages, powering applications across various platforms, including desktop, web, mobile, and embedded systems. To develop Java applications, you need the Java Development Kit (JDK), which includes essential tools like the compiler (javac), debugger, and the Java Runtime Environment (JRE).

In this guide, we’ll walk you through installing OpenJDK on Ubuntu 20.04 LTS, setting up environment variables, and verifying the installation.
Prerequisites
✔ Ubuntu 20.04 LTS (installed and updated)
✔ Terminal access (with sudo privileges)
✔ Stable internet connection
Step 1: Update System Packages
Before installing any new software, it’s best practice to update your system’s package repository:
sudo apt update
Then, upgrade existing packages:
sudo apt upgrade -y
Step 2: Install OpenJDK
Ubuntu’s default repositories include multiple OpenJDK versions (11, 13, 14). To install OpenJDK 14, run:
sudo apt install openjdk-14-jdk -y
Alternative versions:
- JDK 11 (LTS) →
sudo apt install openjdk-11-jdk - JDK 13 →
sudo apt install openjdk-13-jdk
Step 3: Verify Installation
Check the installed Java version:
java --version
Expected output:
openjdk 14.0.2 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 14.0.2+12-Ubuntu-120.04, mixed mode, sharing)
Step 4: Configure Default Java Version (If Multiple JDKs Installed)
If you have multiple JDK versions, set the default using:
sudo update-alternatives --config java
Select the desired version by entering its selection number.
Step 5: Set JAVA_HOME Environment Variable
Many Java applications require the JAVA_HOME variable.
Find Java Installation Path
Run:
sudo update-alternatives --config java
Copy the path (e.g., /usr/lib/jvm/java-14-openjdk-amd64/bin/java).
Edit Environment File
Open /etc/environment in a text editor:
sudo nano /etc/environment
Add the following line (replace the path with yours):
JAVA_HOME="/usr/lib/jvm/java-14-openjdk-amd64"
Save (Ctrl + X, then Y, then Enter).
Apply Changes
Reload the environment file:
source /etc/environment
Verify:
echo $JAVA_HOME
Should display the JDK path.
Step 6: Tast Java Compilation
Create a simple Java file:
nano HelloWorld.java
Paste:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Ubuntu 20.04!");
}
}
Compile & run:
javac HelloWorld.java
java HelloWorld
Expected outputs::
Hello, Ubuntu 20.04!
Final Thoughts
You’ve successfully installed OpenJDK 14 on Ubuntu 20.04 LTS and configured the JAVA_HOME environment variable. Now, you’re ready to develop and run Java applications seamlessly.
For more IT tutorials, stay tuned to our blog!
Tags:
Java, JDK, Ubuntu 20.04, OpenJDK, Programming, Linux
Hashtags:
#Java #Ubuntu #OpenJDK #Programming #Linux #TechGuide