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

Bash Scripting Best Practices Every Beginner Should Know

Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…

1 day ago

How To Create A Self-Signed SSL Certificate Using Bash And OpenSSL

Introduction A self-signed SSL certificate is a certificate that is created and signed by the…

1 day ago

How To Debug Bash Scripts Using bash -x And set Commands

Introduction Debugging is an important part of Bash scripting. When a script does not work…

1 day ago

How To Use Cron Jobs With Bash Scripts For Automation

Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…

1 day ago

How To Use Pipes In Bash Scripts For Command Chaining

Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…

1 day ago

How To Use grep, awk, And sed In Bash Scripts

Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…

2 days ago