Running a Minecraft server on your VPS gives you full control over performance, mods, and player management. This guide covers setup on Ubuntu 22.04 or later.
Recommended VPS Specifications
| Players | RAM | CPU Cores | Storage | BearHost Plan | |---|---|---|---|---| | 1–5 | 2 GB | 2 | 20 GB SSD | VPS S | | 5–15 | 4 GB | 2 | 40 GB SSD | VPS M | | 15–30 | 8 GB | 4 | 60 GB SSD | VPS L | | 30–50+ | 16 GB | 6 | 100 GB SSD | VPS XL |
Step 1: Install Java 21
Minecraft 1.20.5+ requires Java 21:
sudo apt update && sudo apt upgrade -y
sudo apt install openjdk-21-jre-headless -y
java -version
Step 2: Create a Minecraft User
Never run game servers as root:
sudo useradd -r -m -d /opt/minecraft -s /bin/bash minecraft
Step 3: Download the Server
sudo su - minecraft
mkdir server && cd server
wget https://piston-data.mojang.com/v1/objects/LATEST_HASH/server.jar
Replace the URL with the latest server jar link from minecraft.net/download/server.
Step 4: Accept the EULA
java -jar server.jar --nogui
This will fail and generate eula.txt. Accept the EULA:
sed -i 's/eula=false/eula=true/' eula.txt
Step 5: Configure server.properties
Edit server.properties with your preferred settings:
motd=My BearHost Minecraft Server
max-players=20
view-distance=10
simulation-distance=8
difficulty=normal
gamemode=survival
pvp=true
enable-command-block=true
server-port=25565
online-mode=true
Step 6: RAM Allocation Guide
| Server RAM | Allocate (Xms/Xmx) | Remaining for OS | |---|---|---| | 2 GB | 1024M | ~1 GB | | 4 GB | 3072M | ~1 GB | | 8 GB | 6144M | ~2 GB | | 16 GB | 12288M | ~4 GB |
Step 7: Create a systemd Service
Exit the minecraft user and create a service file:
exit
sudo nano /etc/systemd/system/minecraft.service
Paste the following (using Aikar's optimised JVM flags):
[Unit]
Description=Minecraft Server
After=network.target
[Service]
User=minecraft
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xms3072M -Xmx3072M -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 server.jar --nogui
Restart=on-failure
RestartSec=10
StandardInput=null
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl daemon-reload
sudo systemctl enable minecraft
sudo systemctl start minecraft
sudo systemctl status minecraft
Step 8: Open the Firewall
sudo ufw allow 25565/tcp
sudo ufw reload
Step 9: Enable RCON (Remote Console)
Add to server.properties:
enable-rcon=true
rcon.port=25575
rcon.password=YOUR_SECURE_PASSWORD
Install an RCON client:
sudo apt install mcrcon -y
mcrcon -H 127.0.0.1 -P 25575 -p YOUR_SECURE_PASSWORD
Performance Tips
- Use Paper or Purpur instead of vanilla for much better performance
- Pre-generate chunks with the Chunky plugin to reduce lag from exploration
- Lower view-distance to 8 and simulation-distance to 6 on smaller servers
- Disable unused features like spawn-npcs or spawn-animals if not needed
Automatic Backups
Create a backup script:
sudo nano /opt/minecraft/backup.sh
#!/bin/bash
BACKUP_DIR="/opt/minecraft/backups"
SERVER_DIR="/opt/minecraft/server"
DATE=$(date +%Y-%m-%d_%H-%M)
mkdir -p $BACKUP_DIR
tar -czf $BACKUP_DIR/minecraft-$DATE.tar.gz -C $SERVER_DIR world world_nether world_the_end
find $BACKUP_DIR -name "*.tar.gz" -mtime +7 -delete
chmod +x /opt/minecraft/backup.sh
sudo crontab -u minecraft -e
Add: 0 */6 * * * /opt/minecraft/backup.sh to back up every 6 hours.
Connecting to Your Server
In Minecraft, go to Multiplayer > Add Server and enter your VPS IP address. No port is needed if using the default 25565.