A jar started in SSH (or in screen / tmux) dies when that session ends, and it does not come back after a reboot. A systemd unit starts Minecraft as the minecraft user on boot, restarts it if the process exits badly, and gives you systemctl to start, stop, and read logs.
This sits on top of a vanilla Minecraft Java Edition install on a LochStudios KVM VPS. Same minecraft user, same /home/minecraft/server directory, same TCP port 25565. Need that install first? Set up a Minecraft Java Edition server on Linux. Need a VPS? See VPS. On a dedicated server, open a support ticket and we will size the box with you.
This is not Minecraft Bedrock, and it is not a cPanel job. For a first test only, you can still use screen or tmux. Switch to this unit before you walk away.
For Valheim, Rust, CS2, or another binary, use the generic unit instead: Keep a Game Server Running and Auto-Restarting with systemd.
Before you start
- Sign in at the portal, open the VPS service, and keep that page open. Copy the IPv4 from there. Do not guess a hostname.
- Connect with a sudo user, or
rooton a fresh box.
- Connect to your VPS via SSH from macOS or Linux
- Connect to your VPS via SSH from Windows
- Confirm the jar already works once by hand, the EULA is accepted, and port 25565 is open on both the portal Firewall tab and UFW. Recap: Open the Right Firewall Ports for Your Game Server.
- Match
-Xmx/-Xmsto the RAM table in the vanilla article. Do not set the heap to the full VPS size.
If SSH from your computer will not connect, open the console on the same VPS service. That session does not need port 22 from your network.
We document Ubuntu 24.04 LTS. Debian is close. For AlmaLinux or Rocky Linux, open a support ticket and we will match the unit with you.
Step 1: Stop any process already using the port
Two Java processes on 25565 will fight. If you still have the server in SSH, type stop and wait for it to exit. If it is in screen or tmux, attach and do the same.
Confirm nothing is listening:
sudo ss -tulnp | grep 25565
No java line should appear. If a stray process remains, open a support ticket before you kill -9 a world that is still saving.
Step 2: Create the systemd unit
sudo nano /etc/systemd/system/minecraft.service
Paste this. The example heap (4G) matches an 8 GB VPS in the vanilla article. Change it if your VPS is smaller or larger.
[Unit]
Description=Minecraft Server
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=minecraft
Group=minecraft
WorkingDirectory=/home/minecraft/server
ExecStart=/usr/bin/java -Xmx4G -Xms4G -jar server.jar nogui
Restart=on-failure
RestartSec=30
TimeoutStopSec=90
SuccessExitStatus=0 143
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
| Key | Why it is there |
|---|---|
User / Group | Runs as minecraft, not root. |
WorkingDirectory | Where server.jar, eula.txt, server.properties, and the world live. |
ExecStart | The same Java command you used by hand. Keep -Xmx and -Xms equal. nogui skips a desktop window. |
Restart=on-failure | Comes back after a crash. A clean systemctl stop stays stopped. |
RestartSec=30 | Waits 30 seconds so a crash loop does not hammer the disk. |
TimeoutStopSec=90 | Time to save the world after systemctl stop (systemd sends SIGTERM). |
SuccessExitStatus=0 143 | Java often exits 143 after SIGTERM. Treat that as a clean stop. |
Do not add StandardInput=socket. That needs a matching .socket unit and is not how this process is started.
Save the file and exit the editor (in nano: Ctrl+O, Enter, Ctrl+X).
Paper, Fabric, or Forge
- Paper (or vanilla): leave
ExecStartpointing atserver.jar. That is what Add plugins (Paper/Spigot) or mods to a Minecraft server expects. - Fabric: change the jar to
fabric-server-launch.jar(same article). - Forge / NeoForge: point
ExecStartat therun.shthe installer wrote, or open a support ticket and we will wire the unit. Tell us the VPS service, the Minecraft version, and Forge vs NeoForge. Do not put the password in the ticket.
Step 3: Reload systemd and enable on boot
sudo systemctl daemon-reload
sudo systemctl enable minecraft
enable only marks it for the next boot. It does not start the process yet.
Step 4: Start it
sudo systemctl start minecraft
The first start after a world generate can take several minutes. Watch the log:
sudo journalctl -u minecraft -f
Wait until it prints that it is done, then Ctrl+C to leave the log view. You are not attached to the game console. systemctl stop minecraft is the clean stop. Do not use Ctrl+C on the log as a stop, and do not use kill -9.
Step 5: Confirm it is running
sudo systemctl status minecraft
sudo systemctl is-enabled minecraft
sudo ss -tulnp | grep 25565
You want active (running), enabled, and java on 0.0.0.0:25565 or [::]:25565. Listening only on 127.0.0.1 means players outside the VPS cannot join.
Join from Minecraft Java Edition using the IPv4 on the VPS in the portal, port 25565. Do not test only from the VPS itself.
Day-to-day commands
Stop (lets the world save):
sudo systemctl stop minecraft
Restart (after you change server.properties, plugins, or mods):
sudo systemctl restart minecraft
Last 50 log lines:
sudo journalctl -u minecraft -n 50
Follow the log:
sudo journalctl -u minecraft -f
Turn off auto-start (the process can still run until you stop it):
sudo systemctl disable minecraft
After any edit to /etc/systemd/system/minecraft.service:
sudo systemctl daemon-reload
sudo systemctl restart minecraft
Heap size
Leave RAM for the operating system. Use the same heap as the vanilla article:
| VPS RAM | Suggested -Xmx / -Xms |
|---|---|
| 4 GB | 2G |
| 8 GB | 4G |
| 16 GB | 8G to 10G |
A 2 GB VPS is only a smoke test. Plugins and mods want more than vanilla. Raise the heap only when free -h still shows spare RAM. If the kernel is swapping, add swap: Add Swap Space to Your VPS. Watch load with Monitor Server Resources.
Two worlds on one VPS
You can run a second unit (minecraft-creative.service, and so on) with its own WorkingDirectory and its own server-port in server.properties. Open that extra port on the portal Firewall tab and in UFW. Keep each heap small enough that both worlds plus the OS still fit.
If it will not start, or nobody can join
active (failed) or it exits immediately. Read sudo journalctl -u minecraft -n 50. Usual causes: missing server.jar, EULA not accepted, or the minecraft user cannot write the directory.
ls -l /home/minecraft/server/server.jar
sudo chown -R minecraft:minecraft /home/minecraft/server
Unsupported class file or a Java version error. Java does not match that Minecraft line. Check java -version against the table in the vanilla article.
It keeps restarting every 30 seconds. The process is crashing. Lower -Xmx if RAM is gone (free -h), or fix the jar / plugin that is exiting. A crash loop will not heal itself.
Players cannot join after a reboot. Check sudo systemctl status minecraft (did it enable?), then the portal Firewall tab, then sudo ufw status. Details: Open the Right Firewall Ports for Your Game Server.
You wanted to type stop or an op command. systemd has no interactive console. Stop with systemctl stop. For in-game commands, use an op account in Minecraft, or enable RCON in server.properties if you already know that setup. Open a support ticket if you want that wired with us.
Still stuck? Open a support ticket. Tell us the VPS service, the Minecraft version, java -version, and the last 50 journal lines. Do not send the password.
What to do next
- Vanilla install (Java, EULA,
server.properties): Set up a Minecraft Java Edition server on Linux - Plugins (Paper) or mods (Fabric / Forge): Add plugins (Paper/Spigot) or mods to a Minecraft server
- World backups (stop the unit first): Back Up and Restore a Game Server World or Save
- Temporary console session: Run a game server persistently with screen or tmux
- Player ports: Open the Right Firewall Ports for Your Game Server
A step is unclear? Open a support ticket and we will walk through the unit on the VPS with you.