Game Hosting

How to Set Up a Minecraft Java Server on Linux

Install, configure, and run a Minecraft Java Edition server with systemd for auto-restart on boot.

Published May 1, 2025Updated Jun 10, 202610 min readBeginner
Table of Contents

Requirements

  • Minimum 2 GB RAM (4 GB for 10–20 players, 8 GB for 50+ players)
  • 2+ vCPUs (high single-core frequency matters more than core count)
  • Ubuntu 22.04 LTS
  • Java 21 (required for Minecraft 1.20+)

Step 1: Install Java 21

apt update
apt install openjdk-21-jre-headless -y
java -version   # Should show "openjdk 21"

Step 2: Create a Dedicated System User

useradd -r -m -d /opt/minecraft -s /bin/bash minecraft
mkdir -p /opt/minecraft/server
chown -R minecraft:minecraft /opt/minecraft

Step 3: Download the Minecraft Server JAR

cd /opt/minecraft/server
# Get the latest JAR from https://www.minecraft.net/en-us/download/server
sudo -u minecraft wget -O server.jar   https://launcher.mojang.com/v1/objects/latest/server.jar

Step 4: Accept the EULA

sudo -u minecraft bash -c "java -Xmx512M -jar /opt/minecraft/server/server.jar nogui;   echo 'eula=true' > /opt/minecraft/server/eula.txt"

Step 5: Configure server.properties

nano /opt/minecraft/server/server.properties
server-port=25565
max-players=20
difficulty=normal
gamemode=survival
online-mode=true
motd=§aMy Power Down Server
view-distance=10
simulation-distance=8

Step 6: Create a systemd Service

cat > /etc/systemd/system/minecraft.service << EOF
[Unit]
Description=Minecraft Java Server
After=network.target

[Service]
User=minecraft
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xms2G -Xmx4G \
  -XX:+UseG1GC \
  -XX:+ParallelRefProcEnabled \
  -XX:MaxGCPauseMillis=200 \
  -XX:G1NewSizePercent=30 \
  -jar server.jar nogui
ExecStop=/usr/bin/screen -S minecraft -X stuff "stop
"
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable minecraft
systemctl start minecraft

Step 7: Open the Port in UFW

ufw allow 25565/tcp

Monitor and Manage

systemctl status minecraft          # Check status
journalctl -u minecraft -f          # Live logs
systemctl restart minecraft         # Restart server
systemctl stop minecraft            # Stop server
💡 For better performance, consider using Paper or Purpur instead of vanilla — they include significant performance optimizations and plugin support.
MinecraftJavagame hostingLinuxsystemd
Was this article helpful?

Join Our Discord

Connect with our community of gamers and developers

Get instant support, share experiences, and stay updated with the latest news

Join Us On Discord
2026 VPS SaleLIMITED TIME
View Sale Plans