Most guides tell you to run Minecraft in a screen session and call it done. That works until the server reboots and nobody notices for three hours. Here's how to do it properly: Paper server, systemd, correct Java, memory tuning that actually matters.
Java version — get this right first
Minecraft Java edition has hard requirements:
- Minecraft 1.21+ → Java 21
- Minecraft 1.17–1.20 → Java 17
- Minecraft 1.16 and older → Java 8 or 11
Running the wrong version gives you a cryptic crash at startup. Check what's installed:
java -version
Install Java 21 (Ubuntu/Debian):
sudo apt update
sudo apt install -y openjdk-21-jre-headless
If you need multiple Java versions on one server:
sudo update-alternatives --config java
Why Paper, not vanilla
Vanilla Minecraft server is fine for 2-3 players. For anything more, Paper is what you want. It's a fork that fixes hundreds of performance issues in vanilla, exposes better config options, and supports the whole Bukkit/Spigot plugin ecosystem. Nearly everyone running a public or semi-public server uses Paper.
Download the latest Paper build for your Minecraft version from papermc.io. Or grab it directly on the server:
# Replace 1.21.4 and BUILD with actual values from papermc.io
curl -o paper.jar "https://api.papermc.io/v2/projects/paper/versions/1.21.4/builds/BUILD/downloads/paper-1.21.4-BUILD.jar"
Setup
sudo useradd -r -m -d /opt/minecraft -s /bin/bash minecraft
sudo mkdir -p /opt/minecraft/server
sudo mv paper.jar /opt/minecraft/server/
sudo chown -R minecraft:minecraft /opt/minecraft
First run to generate files and accept the EULA:
sudo -u minecraft java -jar /opt/minecraft/server/paper.jar --nogui
It will exit immediately. Then:
sudo -u minecraft sed -i 's/eula=false/eula=true/' /opt/minecraft/server/eula.txt
You can't skip this. Mojang requires it.
Memory flags
The defaults are bad. Minecraft's garbage collector makes the server stutter every few seconds with default settings. Use Aikar's flags — these are widely tested and make a real difference:
java -Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -jar /opt/minecraft/server/paper.jar --nogui
Adjust -Xms and -Xmx to the same value, set to roughly 60-70% of your available RAM. Don't set them different from each other — it causes extra GC pressure. On a 8GB server, use 5G. On 16GB, use 10G.
systemd service
Create /etc/systemd/system/minecraft.service:
[Unit]
Description=Minecraft Paper Server
After=network.target
[Service]
Type=simple
User=minecraft
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xms4G -Xmx4G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -jar /opt/minecraft/server/paper.jar --nogui
Restart=on-failure
RestartSec=10s
StartLimitBurst=3
StartLimitIntervalSec=60s
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable minecraft
sudo systemctl start minecraft
Watch it start:
sudo journalctl -u minecraft -f
You'll see world generation and then Done (Xs)! when it's ready.
Firewall
sudo ufw allow 25565/tcp comment "Minecraft Java"
Default port is 25565. If you change it in server.properties, open that port instead.
server.properties worth changing
# /opt/minecraft/server/server.properties
# How many players
max-players=20
# Requires players to have a paid Minecraft account
online-mode=true
# Render distance — lower = less RAM/CPU on weak servers
view-distance=8
simulation-distance=6
# Disable if you don't want players to go to the Nether
allow-nether=true
# Message of the day
motd=§bMy Server§r §l|§r Have fun
Restart after any change: sudo systemctl restart minecraft
Console access
One thing you lose with systemd over screen: you can't type commands into the server console easily. Two options:
Use RCON — remote console built into Minecraft. Set it up in server.properties:
enable-rcon=true
rcon.port=25575
rcon.password=changeme
Then connect with mcrcon:
sudo apt install -y mcrcon
mcrcon -H localhost -P 25575 -p changeme
Or use screen for the ExecStart and attach when needed — but RCON is cleaner.
Updating Paper
sudo systemctl stop minecraft
sudo -u minecraft mv /opt/minecraft/server/paper.jar /opt/minecraft/server/paper.jar.bak
# download new paper.jar
sudo -u minecraft curl -o /opt/minecraft/server/paper.jar "https://api.papermc.io/v2/..."
sudo systemctl start minecraft
Keep the old jar around until you've confirmed the new one starts clean. Paper updates are usually painless but world corruption from a bad startup isn't.
Backup the world
Minecraft worlds live in /opt/minecraft/server/world/, world_nether/, world_the_end/. Back these up with rsync. Stop the server first or use Paper's /save-off + /save-all before rsyncing to get a consistent state.