Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

How to create a Minecraft server on a VPS

profile picture
Author
Yusuf Yaser
Published
2025-10-21
Time to read
5 minutes reading time

Introduction

This tutorial shows you how to set up your own Minecraft server on a Hetzner Cloud Server. Tested on Ubuntu 24.04 LTS (as of October 2025)

Prerequisites

  • A local device – to connect to the game
  • A Hetzner Cloud Server with Ubuntu to host Minecraft
  • Access as root or a user with sudo privileges
    • Basic configuration, including firewall, should be complete

Initial Server Setup with Ubuntu

Example terminology

  • 203.0.113.1 – Public IP address of your server
  • mcserver – Example user on the server

Step 1 – Create a new user

It is not recommended to work as root permanently. Instead, create a user with sudo privileges:

adduser mcserver
usermod -aG sudo mcserver
su - mcserver

Choose a secure password. You can leave the rest of the information blank.

Step 2 – Prepare the server

Minecraft requires Java and port 25565.

Step 2.1 – Open port 25565

If you are using UFW, activate the rules:

sudo ufw allow proto tcp to any port 25565
sudo ufw allow proto udp to any port 25565
sudo ufw reload
sudo ufw status

If you are using the Hetzner Cloud Firewall:

Direction Protocol Port Source
Inbound TCP 25565 Any IPv4 / IPv6
Inbound UDP 25565 Any IPv4 / IPv6

You can enter this in the Hetzner Console under Firewalls → Rules.

Step

2.2 – Install Java 21

Minecraft 1.21.1 requires Java 17 or newer. Ubuntu 24.04 provides OpenJDK 21 LTS:

sudo apt update
sudo apt install openjdk-21-jdk-headless -y
java --version

Step 3 – Install Minecraft Server

Create a directory for the server:

mkdir ~/mcraftserver
cd ~/mcraftserver

Download the latest server file – either officially from Mojang or PaperMC (recommended):

PaperMC (recommended):

wget -O server.jar https://api.papermc.io/v2/projects/paper/versions/1.21.1/builds/120/downloads/paper-1.21.1-120.jar

Official (Mojang):

wget -O server.jar https://piston-data.mojang.com/v1/objects/0d03b59cc3e1eecbcb5b0b6f0c79e6a19c6b01ce/server.jar

Accept EULA Start the server once to generate the EULA:

java -jar server.jar

Then edit the file:

nano eula.txt

Change:

eula=false

to

eula=true

Save with Ctrl + X, Y, Enter.

Step 4 – Start Minecraft Server

Install the screen tool to run the server in the background:

sudo apt install screen -y
screen -S MinecraftServer

Change to your server directory:

cd ~/MinecraftServer

Start the server (replace with, for example, 4096 for 4 GB RAM):

With recommended JVM flags:

java -Xms512M -Xmx<MEMORY>M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+AlwaysPreTouch -jar server.jar nogui

Example:

java -Xms512M -Xmx4096M -jar server.jar nogui

As soon as you see the message:

[Server thread/INFO]: Done (X.XXXs)! For help, type “help”

the server has started.

Step 5 – Manage screen session

  • Exit session: Ctrl + A, then D
  • Display all sessions:
screen -list
  • Return to session:
screen -r mcraftserver
  • End session:
screen -X -S mcraftserver quit

Step 6 – Change server port

If you want to start multiple servers:

nano server.properties

Change

server-port=25565

e.g. to:

server-port=25567

Then adjust your firewall rules.

Step 7 – Set up automatic restart

Create a start script that automatically restarts the server in case of a crash:

cat <<‘EOF’ > ~/mcraftserver/run.sh
#!/bin/bash
while true; do
  java -Xms512M -Xmx4096M -jar server.jar nogui
  echo “Server will restart in 5 seconds – CTRL+C to cancel.”
sleep 5
done
EOF
chmod +x ~/mcraftserver/run.sh

Start the server with the script:

./run.sh

Step 8 – Connect to the server

Start Minecraft → Multiplayer → Add Server Enter the following address:

<your-server-ip>

or with port:

<your-server-ip>:<port> 

Example:

203.0.113.1:25567

If you are playing locally:

localhost:25565

Conclusion

You have successfully set up your own Minecraft server on a Hetzner Cloud Server. You can now make further adjustments in the server.properties file, install plugins via PaperMC, or set up automatic backups. For better performance, we recommend using PaperMC's JVM optimizations.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue

Discover

#Hetzner4gamers

Take your gaming experience to the next level! Discover which Hetzner server is best for your gaming world.

Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more