Install Java
Eclipse Temurin 25, 21, 17 and 8 from the official Adoptium repository, and switching versions.
4 min read
On this page
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?
| For | Java |
|---|---|
| Minecraft 26.1 and newer | 25 |
| Minecraft 1.20.5 to 1.21.x | 21 |
| Minecraft 1.18 to 1.20.4 | 17 |
| Minecraft 1.16.5 and older, old modpacks | 8 |
| Your own programs | whatever 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
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
apt install -y temurin-21-jreOther versions the same way:
apt install -y temurin-25-jre temurin-17-jre temurin-8-jreTo see what's available:
apt search temurinAlmaLinux and Rocky Linux
Set up the repository
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
EOFInstall Java
dnf install -y temurin-21-jreThe first time, dnf asks whether to import the Adoptium key; -y answers yes. More versions:
dnf install -y temurin-25-jre temurin-17-jre temurin-8-jreCheck that it worked
java -versionThe output looks roughly like this:
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:
update-alternatives --config javaAlmaLinux and Rocky Linux:
alternatives --config javaYou 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:
ls /usr/lib/jvm/A start with a fixed version then looks something like:
/usr/lib/jvm/temurin-17-jre-amd64/bin/java -jar server.jarThe folder name differs between Debian/Ubuntu and AlmaLinux/Rocky; use the one ls shows.
Updates
Java updates arrive with the normal system update:
apt update && apt upgrade # Debian and Ubuntu
dnf upgrade # AlmaLinux and Rocky LinuxRunning Java programs only use the new version after they are restarted.
Common errors
| Message | Cause and fix |
|---|---|
java: command not found | No Java installed yet, or no default set. update-alternatives --config java or alternatives --config java. |
UnsupportedClassVersionError ... class file version 65.0 | The program needs a newer Java. 61 = Java 17, 65 = Java 21, 69 = Java 25. |
Unable to locate package temurin-21-jre | Forgot apt update after adding the repository, or a typo in /etc/apt/sources.list.d/adoptium.list. |
NO_PUBKEY on apt update | The key is missing or not where signed-by points. Run the wget command above again. |
What next
- Minecraft server with Paper.
- Add swap if Java wants more RAM than is free.
- Help: ticket.