How to Install Java on a VPS
A Minecraft server and many other applications need Java. In this tutorial, you’ll install the Java version you need from the official Adoptium (Eclipse Temurin) repository, so you can update it later with one command.
What you need before you start
- A VPS running Ubuntu or Debian.
- A user with sudo privileges.
- An SSH client. More: How to use PuTTY.
Installing Java
-
Check whether Java is already installed
Connect to the server via SSH and enter:
java -versionIf you see a version number, Java is already installed. If you see java: command not found, continue.
-
Update the system
Before installing, update the package list and existing packages:
sudo apt update && sudo apt upgrade -y -
Add the Adoptium repository
Install the required tools:
sudo apt install -y wget apt-transport-https gpgAdd the repository signing key:
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/nullAdd the repository itself. The command detects your system version automatically:
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.listUpdate the package list:
sudo apt update -
Install the Java version you need
Choose the version your application requires:
sudo apt install -y temurin-25-jdksudo apt install -y temurin-21-jdksudo apt install -y temurin-17-jdksudo apt install -y temurin-11-jdksudo apt install -y temurin-8-jdkWhich version does a Minecraft server need?Minecraft 1.20.5 and newer needs Java 21, versions 1.17–1.20.4 need Java 17, and 1.16.5 and older need Java 8. The latest versions may require Java 25, so always check the server requirements.
-
Verify the installation
Enter again:
java -versionIf you see the number of the version you chose, Java is installed correctly.
FAQ
I installed several versions. How do I choose the default?
Enter sudo update-alternatives --config java and pick the number of the version you need from the list.
How do I remove Java?
Use sudo apt remove temurin-21-jdk, replacing 21 with your version. Don’t use rm -rf /usr/lib/jvm, as it deletes all versions and breaks system links.
The application shows “Unsupported class file major version”
The Unsupported class file major version error means the installed Java version is too old. Install a newer one and set it as the default.
Why Temurin instead of Oracle Java?
Eclipse Temurin is a free, open-source OpenJDK build that works the same as Oracle Java, has no licensing restrictions and updates with the system via apt. Java 16 is no longer supported, so use Java 17 instead.
Does this tutorial work on AlmaLinux or Rocky Linux?
No. These systems use the dnf package manager, so the repository is added differently. If you need help, contact us.
What’s next
If you run into trouble, contact us via live chat or email.