Share your love
Set up OpenJDK 19 on Ubuntu 22.04: Free Java Platform

In this guide, we want to teach you to Set up OpenJDK 19 on Ubuntu 22.04. OpenJDK is a free and open-source Java Platform, Standard Edition implementation. It is a community-driven project that was started in 2006.
OpenJDK is published under the GNU General Public License (GPL), one of the most popular free software licenses. OpenJDK aims to offer a free and high-performance alternative to Oracle JDK.
Ubuntu 22.04 ships with default Java 11. Follow the steps below on the Orcacore website to install OpenJDK 19 Ubuntu 22.04.
Table of Contents
Steps To Set up OpenJDK 19 on Ubuntu 22.04
To complete this guide on OpenJDK 19 Ubuntu 22.04, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.
Method 1. Installing OpenJDK 19 Ubuntu 22.04
First, you need to update your local package index with the command below:
sudo apt update
Download OpenJDK 19
At this point, you need to visit the JDK Downloads page to download the latest archive by using the wget command:
sudo wget https://download.java.net/java/GA/jdk19.0.2/fdb695a9d9064ad6b064dc6df578380c/7/GPL/openjdk-19.0.2_linux-x64_bin.tar.gz
Then, extract your downloaded file with the command below:
sudo tar xvf openjdk-19.0.2_linux-x64_bin.tar.gz
Next, move your extracted file to the /opt directory:
sudo mv jdk-19.0.2 /opt/
Configure Java Environment Path on Ubuntu 22.04
At this point, you need to configure the Java home path by using the following command:
sudo tee /etc/profile.d/jdk19.sh <<EOF
export JAVA_HOME=/opt/jdk-19.0.2
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
Source your profile file with the following command:
source /etc/profile.d/jdk19.sh
Verify your Java Home path:
echo $JAVA_HOME
Output
/opt/jdk-19.0.2
Also, you can verify your Java installation by checking its version:
java -version

Method 2. Install OpenJDK 19 From the Apt Repository
Another way that you can use to install Java 19, is to use the Apt repository on Ubuntu 22.04.
First, you need to update your local package index with the command below:
sudo apt update
Then, use the command below to install Java 19:
apt install openjdk-19-jre-headless -y
Verify your Java installation by checking its version:
java -version

Create a Sample Project with OpenJDK 19
At this point, we will show you how to create a sample project to see that your Java is working correctly on Ubuntu 22.04. Create and open the hello world file with your favorite text editor like nano editor or vi editor:
vi HelloWorld.java
Add the following content to the file:
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
When you are done, save and close the file.
Then, compile and run your Java code:
java HelloWorld.java
Output
Hello, World
That’s it, you are done.
Conclusion
If you’re a developer or user working with Java applications, OpenJDK 19 on Ubuntu 22.04 provides the tools and features needed to build, run, and optimize modern Java-based software solutions. At this point, you have learned to Set up OpenJDK 19 or Java 19 on Ubuntu 22.04.
Hope you enjoy it. You may also like to read the following articles:
How do I find my OS details in Ubuntu?
How to Install Caddy Webserver on Ubuntu 24.04
How to Install PHP on Ubuntu 24.04
How to Enable or Disable AppArmor on Ubuntu 24.04
Setting a Static IP Address in Ubuntu 24.04 via GUI