Skip to content
CitexNode
All guides

Install Java

Eclipse Temurin 25, 21, 17 and 8 from the official Adoptium repository, and switching versions.

4 min read

Applies to Debian 12/13, Ubuntu 22.04/24.04, AlmaLinux 9 and Rocky Linux 9. We install Eclipse Temurin, the free Java builds from Adoptium, from their official package repository. Updates then come through apt or dnf like any other package.

The commands run as root. With a sudo user, put sudo in front.

Which version do you need?

ForJava
Minecraft 26.1 and newer25
Minecraft 1.20.5 to 1.21.x21
Minecraft 1.18 to 1.20.417
Minecraft 1.16.5 and older, old modpacks8
Your own programswhatever the program requires; if unsure, the newest LTS

Paper and many modpacks state the minimum version on their site. You can install several versions side by side.

For servers, the JRE is enough (temurin-21-jre). If you want to compile Java code on the server, take the JDK (temurin-21-jdk).

Debian and Ubuntu

Set up the repository

bash
apt install -y wget gpg ca-certificates
install -d -m 0755 /etc/apt/keyrings
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor -o /etc/apt/keyrings/adoptium.gpg
echo "deb [signed-by=/etc/apt/keyrings/adoptium.gpg] https://packages.adoptium.net/artifactory/deb $(. /etc/os-release && echo "$VERSION_CODENAME") main" > /etc/apt/sources.list.d/adoptium.list
apt update

$VERSION_CODENAME is the name of your release (bookworm, trixie, jammy, noble); the command fills it in for you.

Install Java

bash
apt install -y temurin-21-jre

Other versions the same way:

bash
apt install -y temurin-25-jre temurin-17-jre temurin-8-jre

To see what's available:

bash
apt search temurin

AlmaLinux and Rocky Linux

Set up the repository

bash
cat > /etc/yum.repos.d/adoptium.repo <<'EOF'
[Adoptium]
name=Adoptium
baseurl=https://packages.adoptium.net/artifactory/rpm/rhel/9/$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/public
EOF

Install Java

bash
dnf install -y temurin-21-jre

The first time, dnf asks whether to import the Adoptium key; -y answers yes. More versions:

bash
dnf install -y temurin-25-jre temurin-17-jre temurin-8-jre

Check that it worked

bash
java -version

The output looks roughly like this:

text
openjdk version "21.0.9" 2025-10-21 LTS
OpenJDK Runtime Environment Temurin-21.0.9+10 (build 21.0.9+10-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.9+10 (build 21.0.9+10-LTS, mixed mode, sharing)

What matters is the first number and the word Temurin. Your exact update version will be newer.

Switch between versions

With several versions installed, one of them is the default for the java command.

Debian and Ubuntu:

bash
update-alternatives --config java

AlmaLinux and Rocky Linux:

bash
alternatives --config java

You get a numbered list; type the number you want and press Enter. Afterwards java -version shows the new version.

Call a specific version directly

For a server that always needs the same version, the full path is safer than the default. Find the paths with:

bash
ls /usr/lib/jvm/

A start with a fixed version then looks something like:

bash
/usr/lib/jvm/temurin-17-jre-amd64/bin/java -jar server.jar

The folder name differs between Debian/Ubuntu and AlmaLinux/Rocky; use the one ls shows.

Updates

Java updates arrive with the normal system update:

bash
apt update && apt upgrade        # Debian and Ubuntu
dnf upgrade                      # AlmaLinux and Rocky Linux

Running Java programs only use the new version after they are restarted.

Common errors

MessageCause and fix
java: command not foundNo Java installed yet, or no default set. update-alternatives --config java or alternatives --config java.
UnsupportedClassVersionError ... class file version 65.0The program needs a newer Java. 61 = Java 17, 65 = Java 21, 69 = Java 25.
Unable to locate package temurin-21-jreForgot apt update after adding the repository, or a typo in /etc/apt/sources.list.d/adoptium.list.
NO_PUBKEY on apt updateThe key is missing or not where signed-by points. Run the wget command above again.

What next