How to Install Java 17 on Ubuntu 22.04
Introduction
Java 17 is the latest Long-Term Support (LTS) release and is widely used by developers, DevOps engineers, and system administrators.
In this guide, you’ll learn how to install and configure Java 17 on Ubuntu 22.04 step by step, including environment variables and optional developer tools like Maven and Gradle.
Step 1: Update Your System
sudo apt update && sudo apt upgrade -y
Step 2: Install OpenJDK 17
sudo apt install openjdk-17-jdk -y
Step 3: Verify Installation
java -version
If the installation is successful, you will see output confirming Java 17.
Step 4: Set JAVA_HOME Environment Variable
It’s a good practice to set the JAVA_HOME
variable:
echo "export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" | sudo tee -a /etc/profile
echo "export PATH=$JAVA_HOME/bin:$PATH" | sudo tee -a /etc/profile
source /etc/profile
Step 5: Configure Alternatives (Optional)
If you have multiple versions of Java installed, configure alternatives:
sudo update-alternatives --config java
Step 6: Test JAVA_HOME
echo $JAVA_HOME
Step 7: Install Maven (Optional for Developers)
Maven is a popular build automation tool for Java projects:
sudo apt install maven -y
Step 8: Install Gradle (Optional for DevOps/Automation)
Gradle is widely used for CI/CD pipelines and automation:
sudo apt install gradle -y
Conclusion
You have successfully installed Java 17 on Ubuntu 22.04.
This setup ensures developers, administrators, and DevOps engineers can run modern Java applications smoothly.
For production workloads, setting JAVA_HOME and adding build tools like Maven or Gradle is highly recommended.
SEO Keywords: Install Java 17 Ubuntu 22.04, OpenJDK 17 setup, Ubuntu Java tutorial, Java 17 LTS Linux installation, Java development Ubuntu