Installation Guide for Java 22 (OpenJDK 22.0.1) on Ubuntu Server
Download Java 22 Package
# wget https://download.java.net/java/GA/jdk22.0.1/c7ec1332f7bb44aeba2eb341ae18aca4/8/GPL/openjdk-22.0.1_linux-x64_bin.tar.gz
Extract the Archive
Once the download completes, extract the tar.gz archive to a directory where you want to install Java. Typically, this can be /opt for system-wide installations:
# mkdir -p /opt/java/openjdk-22
# tar -xzvf openjdk-22.0.1_linux-x64_bin.tar.gz -C /opt/java/openjdk-22 --strip-components=1
Set Java Environment Variables
To use Java 22, you should set the JAVA_HOME and PATH environment variables. Edit your shell profile configuration file (e.g., ~/.bashrc, ~/.bash_profile, or /etc/profile.d/java.sh):
Open the file in a text editor (using vim in this example):
# vim /etc/profile.d/java.sh
Add the following lines to set JAVA_HOME and update the PATH:
export JAVA_HOME=/opt/java/openjdk-22
export PATH=$JAVA_HOME/bin:$PATH
Load the Environment Variables
To apply the changes to your current session, either log out and log back in, or source the script you just modified:
# source /etc/profile.d/java.sh
Verify Installation
Check if Java 22 is installed correctly by running:
# java -version