Installing OpenJDK 17 on Ubuntu 22.04 and 20.04
OpenJDK 17 is the newest LTS Java release that’s already making its way into production workloads. If you’re running Ubuntu 20.04 or 22.04 and need a clean install, this short guide will get you up and running—no fuss, no mysterious errors.
Why OpenJDK 17 Matters for Your Projects
You might wonder why anyone would bother switching to the latest JDK. I’ve seen developers stuck on Java 11 because their build tools refuse to compile code that uses new language features like sealed classes or pattern matching. Switching to OpenJDK 17 unlocks those goodies without dragging in a full Oracle JRE.
Prerequisites Before You Start
1. Update the system
sudo apt update && sudo apt upgrade -y
Keeping packages current prevents version conflicts that could bite you later.
2. Check if another Java is already installed
java --version
If a different JDK shows up, decide whether to keep it or remove it—mixing runtimes can trip your IDE into pointing at the wrong compiler.
Installing From Ubuntu Repositories (Easiest Path)
Ubuntu 22.04 ships OpenJDK 17 in its default repos, while Ubuntu 20.04 requires a small tweak:
- For Ubuntu 22.04
sudo apt install openjdk-17-jdk
- For Ubuntu 20.04
The official repo contains only JDK 11 by default. Add the “jdk‑17” PPA:
sudo add-apt-repository ppa:openjdk-r/ppa sudo apt update sudo apt install openjdk-17-jdk
The PPA step is necessary because Ubuntu 20.04’s base repos lag behind in JDK versions; the PPA keeps you on lockstep with the upstream OpenJDK releases.
Setting Java 17 as the Default Runtime
After installation, make sure the system picks the right one:
sudo update-alternatives --config java
Select the number that points to /usr/lib/jvm/java-17-openjdk-amd64/bin/java. This step is crucial if you have multiple Java versions; otherwise your shell could still be calling Java 11 silently.
Verifying Your Install
java --version # should output something like: # openjdk version "17.0.8" 2023-07-18 LTS
If that matches, congratulations—your environment is ready for modern Java projects.
Troubleshooting Common Issues
- “command not found” after sudo apt install – Double‑check that the package name was typed correctly. Ubuntu’s naming convention uses hyphens: openjdk-17-jdk.
- Maven complains about unsupported Java version – Ensure you’re running Maven with the same JDK by setting JAVA_HOME:
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
Add that line to your .bashrc if it works.
- IDE still points to Java 11 – In Eclipse or IntelliJ, go to the project’s SDK settings and switch to the newly installed JDK. IDEs often cache the last used runtime.
That’s all there is to it: a couple of commands and a few sanity checks. If you hit any snags, feel free to ping the community; I’ve seen people stuck on subtle PATH issues that are easy to solve once spotted.