Skip to main content

How to Create a Minecraft Server on a VPS or Dedicated Server

This guide explains how to install and configure a Minecraft Java Edition server on your VPS or dedicated Linux server.

Order a Serverโ€‹

To host your Minecraft server, HostMyServers offers several gaming-optimized options:

Prerequisitesโ€‹

  • SSH access as root or user with sudo privileges
  • Up-to-date Debian/Ubuntu system
  • Minimum 2 GB of RAM (4 GB recommended for 10+ players)
  • Port 25565 accessible (TCP)
  • Stable internet connection

Required Configurationโ€‹

Number of playersMinimum RAMRecommended RAM
1-51 GB2 GB
5-102 GB4 GB
10-204 GB6 GB
20+6 GB8 GB+

System Updateโ€‹

sudo apt update && sudo apt upgrade -y

Java Installationโ€‹

Minecraft 1.17+ requires Java 17 minimum. For recent versions (1.20+), Java 21 is recommended.

sudo apt install -y openjdk-21-jdk

Verify installationโ€‹

java --version

You should see output similar to:

openjdk 21.0.x 2024-xx-xx
OpenJDK Runtime Environment (build 21.0.x+xx-xx)
OpenJDK 64-Bit Server VM (build 21.0.x+xx-xx, mixed mode, sharing)

Creating a Dedicated Userโ€‹

For security reasons, never run the server as root. Create a dedicated user:

sudo adduser --system --home /opt/minecraft --shell /bin/bash minecraft

Installing Required Toolsโ€‹

sudo apt install -y screen wget curl unzip
  • screen: keeps the server running after SSH disconnection
  • wget/curl: for downloading files
  • unzip: for extracting archives

Downloading Minecraft Serverโ€‹

Connect as minecraft userโ€‹

sudo -u minecraft bash
cd /opt/minecraft
mkdir server
cd server

Download the official serverโ€‹

Get the link for the latest version from minecraft.net/download/server then:

wget -O server.jar https://piston-data.mojang.com/v1/objects/XXXXXXX/server.jar
Note

Replace the URL with the official link for your desired version.

EULA Acceptanceโ€‹

You must accept the Minecraft license agreement:

echo "eula=true" > eula.txt

First Launchโ€‹

Launch the server for the first time to generate configuration files:

java -Xms1G -Xmx2G -jar server.jar nogui

Memory parameters:

  • -Xms1G: initial memory (1 GB)
  • -Xmx2G: maximum memory (2 GB)
  • nogui: disables graphical interface

Stop the server with stop or Ctrl+C after the first launch.

Server Configurationโ€‹

Edit the server.properties file according to your needs:

nano server.properties

Important Settingsโ€‹

# Server port (default: 25565)
server-port=25565

# Maximum number of players
max-players=20

# Game mode (survival, creative, adventure, spectator)
gamemode=survival

# Difficulty (peaceful, easy, normal, hard)
difficulty=normal

# Message displayed in server list
motd=My Minecraft Server

# Render distance (reduce if lag)
view-distance=10

# Enable whitelist
white-list=false

# Online mode (Mojang account verification)
online-mode=true

# Enable PvP
pvp=true

# Spawn protection (radius in blocks)
spawn-protection=16

Firewall Configurationโ€‹

Open the Minecraft port in the firewall:

With UFWโ€‹

sudo ufw allow 25565/tcp
sudo ufw reload

With iptablesโ€‹

sudo iptables -A INPUT -p tcp --dport 25565 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4

Running with screenโ€‹

To keep the server running after SSH disconnection:

Start the server in screenโ€‹

screen -S minecraft
cd /opt/minecraft/server
java -Xms1G -Xmx2G -jar server.jar nogui

Detach the sessionโ€‹

Press Ctrl+A then D to detach the session.

Return to the sessionโ€‹

screen -r minecraft

List sessionsโ€‹

screen -ls

Configuration as systemd Serviceโ€‹

For automatic startup at server boot:

Create the service fileโ€‹

sudo nano /etc/systemd/system/minecraft.service

File content:

[Unit]
Description=Minecraft Java Server
After=network.target

[Service]
User=minecraft
WorkingDirectory=/opt/minecraft/server
ExecStart=/usr/bin/java -Xms1G -Xmx2G -jar /opt/minecraft/server/server.jar nogui
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure
RestartSec=20
StandardInput=null

[Install]
WantedBy=multi-user.target

Enable and start the serviceโ€‹

sudo systemctl daemon-reload
sudo systemctl enable minecraft.service
sudo systemctl start minecraft.service

Management commandsโ€‹

# Check status
sudo systemctl status minecraft.service

# Stop server
sudo systemctl stop minecraft.service

# Restart server
sudo systemctl restart minecraft.service

# View logs
sudo journalctl -u minecraft.service -f

Server Managementโ€‹

Useful Console Commandsโ€‹

Once connected to the server console (via screen):

CommandDescription
stopStops the server properly
save-allSaves the world
listShows connected players
op <player>Gives admin rights to a player
deop <player>Removes admin rights
kick <player>Kicks a player
ban <player>Bans a player
whitelist add <player>Adds a player to whitelist
whitelist remove <player>Removes a player from whitelist
gamemode <mode> <player>Changes game mode
difficulty <level>Changes difficulty

Performance Optimizationโ€‹

Optimized Startup Scriptโ€‹

Create a launch script with optimized flags:

nano /opt/minecraft/server/start.sh
#!/bin/bash
cd /opt/minecraft/server

java -Xms2G -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 server.jar nogui

Make the script executable:

chmod +x /opt/minecraft/server/start.sh

Reduce Lagโ€‹

In server.properties:

# Reduce render distance
view-distance=8

# Reduce simulation distance
simulation-distance=6

# Limit entities
max-tick-time=60000

Automatic Backupโ€‹

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-%S)

mkdir -p $BACKUP_DIR

# World backup
tar -czf $BACKUP_DIR/world_$DATE.tar.gz -C $SERVER_DIR world world_nether world_the_end

# Delete backups older than 7 days
find $BACKUP_DIR -name "world_*.tar.gz" -mtime +7 -delete

echo "Backup completed: world_$DATE.tar.gz"
chmod +x /opt/minecraft/backup.sh

Schedule Backupโ€‹

sudo crontab -e

Add:

# Daily backup at 4 AM
0 4 * * * /opt/minecraft/backup.sh

Connecting to the Serverโ€‹

Players can connect using:

  • Address: YOUR_SERVER_IP or your_domain.com
  • Port: 25565 (default)

In Minecraft: Multiplayer โ†’ Add Server โ†’ Enter address

Troubleshootingโ€‹

Server won't startโ€‹

  • Check logs: tail -f /opt/minecraft/server/logs/latest.log
  • Verify Java is installed: java --version
  • Verify EULA is accepted: cat eula.txt

Players can't connectโ€‹

  • Verify port 25565 is open: sudo ufw status
  • Verify server is running: sudo systemctl status minecraft.service
  • Test port: nc -zv SERVER_IP 25565

Performance issuesโ€‹

  • Increase allocated RAM (-Xmx)
  • Reduce view-distance in server.properties
  • Use Paper or Spigot instead of vanilla server for better performance