NewHalo Edge 3 is here: HTTP/3 everywhere and 42 edge locations.Learn more
Docs / Game servers

Set up a Minecraft Java Edition server

Game servers10 min readUbuntu 24.04 LTS

This guide installs the official Minecraft Java Edition server on your VPS, accepts its end user license agreement honestly, and starts your first world. You will run it under its own unprivileged user so that a problem in the game cannot affect the rest of the system.

Before you begin

  • An Ubuntu 24.04 LTS VPS with a sudo user (this guide uses alex) and enough memory for your player count. The resource article explains how to size it.
  • A Minecraft Java Edition account that owns the game. Players need their own licensed copies to join.
  • A web browser to visit the official Minecraft download page, which lists the server file for each version.

Step 1: Install Java

The Minecraft server is a Java program. Recent Minecraft versions need Java 21, which Ubuntu 24.04 provides as an official package. The "headless" package installs only what a server needs, without desktop components. The wget tool downloads the server file.

sudo apt update
sudo apt install -y openjdk-21-jre-headless wget
java -version

The last command confirms the installed version. Expected output starts like this, though the exact patch number will differ:

openjdk version "21.0.x" 2025-07-15
OpenJDK Runtime Environment (build 21.0.x+...)

Check the official download page for your chosen Minecraft version. If it asks for a newer Java, install that version instead.

Step 2: Create a dedicated user and folder

Run the server as its own system account. The account has no login shell, so nobody can sign in as it, and it can only write inside its own folder.

sudo useradd --system --home-dir /opt/minecraft --shell /usr/sbin/nologin minecraft
sudo mkdir -p /opt/minecraft
sudo chown minecraft:minecraft /opt/minecraft

The --system flag creates an account meant for services, and chown hands the new folder to it.

Step 3: Download the official server file

Open the official Minecraft download page in your browser, find the Minecraft Java Edition server section, and copy the link to the server.jar file for the version you want. Only use files from that official page. Do not use unofficial mirrors, modified servers, or copies from file-sharing sites, since they may contain malware, and they are not licensed for this use.

sudo wget -O /opt/minecraft/server.jar 'PASTE-OFFICIAL-LINK-HERE'
sudo chown minecraft:minecraft /opt/minecraft/server.jar
ls -lh /opt/minecraft

Replace PASTE-OFFICIAL-LINK-HERE with the link you copied, keeping the single quotes. The final listing should show server.jar with a size of several megabytes.

Step 4: Run once and accept the EULA

The first run creates the configuration files, then stops and asks you to accept the Minecraft End User License Agreement. Read it at the official Minecraft site before you agree. Run the server once, in the foreground, as the minecraft user:

sudo -u minecraft sh -c 'cd /opt/minecraft && java -Xms1G -Xmx2G -jar server.jar nogui'

The output includes a line saying you need to agree to the EULA, and the server exits. The -Xms1G -Xmx2G options set the starting and maximum memory for Java. Change them to match your plan. Now record your agreement by changing one line in eula.txt:

sudo -u minecraft sed -i 's/eula=false/eula=true/' /opt/minecraft/eula.txt
grep eula /opt/minecraft/eula.txt

Expected output: eula=true. Changing this line is your own choice, and it means you have read and accepted the terms.

Step 5: Start the server once and keep online mode on

Run the server again. This time it generates the world. When you see a line starting with Done, the server is ready. Type stop and press Enter to shut it down cleanly.

sudo -u minecraft sh -c 'cd /opt/minecraft && java -Xms1G -Xmx2G -jar server.jar nogui'
[Server thread/INFO]: Done (12.345s)! For help, type "help"

Next, open server.properties and check the setting that verifies player accounts:

grep online-mode /opt/minecraft/server.properties

It must read online-mode=true. This makes the server check every player against the official Minecraft account service, so usernames cannot be impersonated. Offline mode, which turns this check off, lets anyone join with any name, and it is a common way for accounts to be stolen or griefed. Leave it on.

Step 6: Open the game port in the firewall

Minecraft Java listens on TCP port 25565 by default. Allow SSH first so that you keep your own access, then allow the game port and turn on the firewall.

sudo ufw allow OpenSSH
sudo ufw allow 25565/tcp
sudo ufw --force enable
sudo ufw status

The status output lists both allowed rules. Players connect to your server's address, such as 203.0.113.10, or to a hostname that points at it.

Tip: Set up the server as a background service next, using the systemd article, so it starts on boot and keeps running after you close your SSH session.

Troubleshooting

  • "Unsupported class file major version" in the output: the Java version is too old for this Minecraft release. Install Java 21 as shown, and confirm with java -version.
  • Server exits with "Could not reserve enough space": the -Xms or -Xmx value is larger than the memory available. Lower both, then try again.
  • Players see "Can't connect to server": confirm the server is running (the console shows Done), and that the firewall rule for 25565 exists. Check from your computer with a Minecraft client, not with a browser.
  • "Failed to verify username": the player's account is not valid, or the server's clock is wrong. Check the time with timedatectl.

Next steps

Your world is generated and the server works. Next, the systemd article runs it as a service that starts on boot and restarts after a crash. The allowlist article then controls who may join, and the backup article protects your world.

Something not working? Chat or email our support team and we will help you get unstuck.

Contact support