How To

Install Java on Ubuntu 22.04 With OpenJDK and Oracle JDK

Java remains one of the most widely used programming languages for enterprise applications, Android development, cloud services, and backend systems. If you want to Install Java on Ubuntu 22.04, Ubuntu provides several reliable options, including OpenJDK and Oracle JDK.

Whether you are building Java applications, running Minecraft servers, or deploying enterprise software, setting up Java on Ubuntu is simple and beginner-friendly.

Why Developers Install Java on Ubuntu Systems

Many modern applications depend on Java to function properly. Development tools, automation platforms, and large-scale enterprise frameworks often require a specific Java version.

Ubuntu 22.04 includes OpenJDK packages directly in its official repositories, making installation fast and secure. Users who need Oracle’s commercial Java release can also install Oracle JDK manually.

Before installing Java, it’s a good idea to check whether Java already exists on your system:

java -version

If Java is missing, Ubuntu will display a command-not-found message.

Install Java on Ubuntu Using OpenJDK

The easiest way to install Java is through Ubuntu’s package manager. First, update the package list:

sudo apt update

Next, install OpenJDK 17, which is the default long-term support release for Ubuntu 22.04:

sudo apt install openjdk-17-jdk

After installation finishes, confirm the installed version:

java -version

You should now see details showing OpenJDK 17 running on your Ubuntu machine.

If your application requires another Java release, Ubuntu also supports packages such as OpenJDK 11 and OpenJDK 21.

Install Java on Ubuntu With Oracle JDK

Some enterprise applications specifically require Oracle Java. In that case, download the official Debian package from Oracle’s Java archive.

After downloading the package, install it using:

sudo apt install ./jdk-21_linux-x64_bin.deb

Oracle JDK includes additional enterprise-focused features and commercial support options. However, OpenJDK remains the preferred choice for most Linux users because it is fully open source.

Configure Default Java Version

If multiple Java versions are installed, Ubuntu allows you to switch between them easily.

Run the following command:

sudo update-alternatives --config java

Ubuntu will display a list of installed Java versions. Simply choose the version you want as the system default.

This feature is extremely useful for developers testing software across different Java environments.

Set JAVA_HOME Environment Variable

Many Java applications require the JAVA_HOME variable to locate the Java installation directory.

First, identify the installed Java path:

sudo update-alternatives --config java

Then edit the environment file:

sudo nano /etc/environment

Add the following line:

JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"

Save the file and reload the environment settings.

Final Thoughts

Learning how to Install Java on Ubuntu 22.04 is essential for developers, system administrators, and DevOps engineers. OpenJDK works perfectly for most workloads, while Oracle JDK remains available for specialized enterprise requirements.

Once Java is installed and configured, you can begin developing applications, running Java-based services, or deploying enterprise platforms directly from your Ubuntu environment.

Cyber Defence

Recent Posts

Best OSINT Tools for Journalists 2026: Verify Sources, Images and Claims

Journalists use OSINT to verify public information before publishing. In 2026, misinformation, AI-generated images, fake…

7 hours ago

Install Docker on Ubuntu 20.04: Complete Step-by-Step Guide

Docker is an open-source platform that lets you package and run applications inside containers. Each container…

17 hours ago

Install PostgreSQL on Ubuntu: Database Setup and Admin Guide

PostgreSQL (often called Postgres) is an open-source relational database system. It supports advanced features like JSON…

18 hours ago

Install Xrdp Remote Desktop on Ubuntu: Setup and Connect

Xrdp is an open-source server that lets you connect to your Ubuntu machine from another computer…

18 hours ago

Tomcat 9 on Ubuntu 20.04: Install, Configure, and Start

Apache Tomcat is an open-source web server and Java servlet container. It is one of the…

19 hours ago

Automatic Updates on Ubuntu: Set Up unattended-upgrades

Keeping your Ubuntu system updated is one of the best ways to protect it. Security…

20 hours ago