Install Oracle Java 17 LTS on Debian 11: A Step‑by‑Step Guide
You’ll learn how to download the official Oracle JDK 17 LTS binary, verify its integrity, install it into /opt/java, and make it the default runtime for your system. I’ll also point out pitfalls that trip up folks who blindly use apt instead of the real Oracle package.
Why choose Oracle Java 17 LTS over OpenJDK?
Oracle’s JDK still ships with some features missing from the community build, like certain native libraries and better JVM tuning options. If you’re running enterprise‑grade Java apps that rely on those extras—or if your license agreement mandates Oracle—this is the route to go.
Prerequisites on Debian 11
1. A fresh Debian 11 installation (bullseye) with sudo privileges.
2. Internet connectivity to reach Oracle’s download site.
3. Basic utilities: wget, tar, and update-alternatives.
sudo apt update && sudo apt install -y wget tar
Downloading the .tar.gz from Oracle’s site
Oracle hosts the JDK as a compressed archive; you’ll need to accept the license manually. I usually use wget with the signed URL:
# Grab the latest 17 LTS build for Linux x64 JDK_URL="https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz" wget --header "Cookie: oraclelicense=accept-securebackup-cookie" "$JDK_URL"
The cookie header tricks Oracle into giving you the file without a browser prompt. Skipping it results in a 403 error.
Verifying the checksum
Oracle publishes SHA‑256 digests on the download page. After downloading, run:
sha256sum jdk-17_linux-x64_bin.tar.gz
Cross‑check the output with Oracle’s listed digest. If it doesn’t match, re‑download or fetch from a mirror.
Extracting to /opt/java
Oracle recommends installing under /opt, keeping system packages separate:
sudo mkdir -p /opt/java sudo tar --strip-components=1 -xzf jdk-17_linux-x64_bin.tar.gz -C /opt/java
--strip-components=1 removes the top‑level folder, so you get /opt/java/bin, not /opt/java/jdk-17.../bin. This simplifies path handling later.
Creating a system link with update-alternatives
Now let Debian know about this new JDK:
sudo update-alternatives --install /usr/bin/java java /opt/java/bin/java 2000 sudo update-alternatives --install /usr/bin/javac javac /opt/java/bin/javac 2000
The 2000 priority ensures Oracle’s JDK wins over any OpenJDK package you might have installed.
Setting environment variables
If you want JAVA_HOME available for scripts or IDEs, add it to /etc/profile.d/java.sh:
sudo tee /etc/profile.d/java.sh <<'EOF' export JAVA_HOME=/opt/java export PATH="$JAVA_HOME/bin:$PATH" EOF chmod +x /etc/profile.d/java.sh
Source the file or log out/in to apply changes.
Testing your install
java -version # should show something like: # openjdk version "17.0.2" 2023-01-17 LTS # OpenJDK Runtime Environment Oracle (build 17.0.2+8-LTS)
If you see “OpenJDK” in the output, you’re still on the community build—double‑check the path. The oracle string confirms the right JDK.
Troubleshooting common errors
- “Could not find java executable” – Make sure /opt/java/bin is first in your $PATH.
- App fails to start after an apt upgrade – Sometimes upgrading libc6 pulls in a conflicting OpenJDK package. Remove it with sudo apt remove --purge openjdk-17-jre-headless.
- “License agreement not accepted” – If you used a mirror that forces the prompt, download directly from Oracle or use wget as shown above.
That’s it. You’ve got an Oracle Java 17 LTS installation on Debian 11, ready for production workloads and free of the bloat that sometimes comes with packaged JDKs.