Step-by-step: Set Up a Minecraft Server from Scratch

Servidores de jogos · By · Published on · Updated on · 10 min read

Backlit laptop keyboard with dark screen and blurred digital elements
Neutral tech-style image suitable for server setup guides Photo: Rafael Minguet Delgado / Pexels

This guide shows how to set up a Minecraft server from scratch on Linux, covering Java, firewall configuration, a systemd service, world properties, ports and backups. You’ll get the essential commands, hosting considerations, and how to verify the server is online so friends can connect securely.

1) Prerequisites and server planning

Before you run commands, define the goal: how many players, whether you'll use mods/plugins, and where you’ll host. That determines needed CPU, RAM, disk and network. For most setups, a modern 64-bit Linux (e.g., Ubuntu Server LTS) with sudo access is sufficient.

Resource estimates by player count are approximate. Usage depends on map complexity, redstone, entities and plugins. Start small, monitor performance and adjust.

Hosting options include a home PC, VPS or cloud provider. VPS/cloud makes getting a public IP and higher availability easier. VMs are common; containers can work but require extra care for I/O and persistent storage.

If using cloud, weigh the cost per vCPU/RAM/egress and choose a nearby region. Also check how to open firewall ports on the provider platform.

  • Access: a user with sudo and SSH enabled.
  • System: up-to-date 64-bit Linux.
  • Java: OpenJDK 17 (modern servers use this version).
  • Network: TCP port 25565 open inbound.
  • Optional domain: provides an easy address for the server.

2) Prepare Linux and install Java (OpenJDK 17)

Create a dedicated user, install Java and set up a basic firewall. You need sudo access. Use UFW to limit open ports.

Keep SSH port (22) open so you don’t lose remote access. 25565 is the default Minecraft port (Java Edition).

# Atualize pacotes e instale Java 17 e UFW
sudo apt update && sudo apt -y upgrade
sudo apt -y install openjdk-17-jre-headless ufw

# Crie usuário e diretório do servidor
sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft
sudo mkdir -p /opt/minecraft/server
sudo chown -R minecraft:minecraft /opt/minecraft

# Firewall básico: mantém SSH e abre porta do Minecraft
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 25565/tcp
sudo ufw enable
sudo ufw status numbered

# Verifique a versão do Java
java -version

3) Download the server, first run and the EULA

You need the server file (server.jar). Download it from the official site or transfer it from your PC. Read the EULA and accept it consciously. The first run creates files like eula.txt and server.properties.

After the files are generated, accept the EULA and run again to validate. Use memory allocation appropriate to your hardware and player count.

  • If transferring from your PC: use scp or SFTP to /opt/minecraft/server.
  • The first run may stop and ask you to accept the EULA: this is expected.
  • Adjust -Xms and -Xmx to match available RAM (e.g., 2G, 4G).
# Entre na pasta do servidor
sudo -u minecraft bash -lc 'cd /opt/minecraft/server && pwd'

# Exemplo: transfira o server.jar do seu computador para o servidor (rode no seu computador)
# scp server.jar usuario@SEU_SERVIDOR:/opt/minecraft/server/server.jar

# Primeira execução para gerar arquivos (pode encerrar com erro pedindo EULA)
sudo -u minecraft bash -lc 'cd /opt/minecraft/server && java -Xms2G -Xmx2G -jar server.jar nogui || true'

# Aceite a EULA após ler (edite manualmente ou use sed)
sudo -u minecraft bash -lc 'cd /opt/minecraft/server && sed -i "s/eula=false/eula=true/" eula.txt'

# Segunda execução de teste
sudo -u minecraft bash -lc 'cd /opt/minecraft/server && java -Xms2G -Xmx2G -jar server.jar nogui'

4) Run the server as a service (systemd)

To run the server in the background and enable automatic restarts, create a systemd service. This makes start/stop, logging and boot auto-start easier.

Set memory (-Xms/-Xmx) in ExecStart and adjust to your hardware. Avoid allocating 100% of system RAM so the OS has headroom.

# Crie o unit file do systemd
sudo tee /etc/systemd/system/minecraft.service > /dev/null <<'EOF'
[Unit]
Description=Minecraft Server
After=network.target

[Service]
WorkingDirectory=/opt/minecraft/server
User=minecraft
Group=minecraft
Restart=on-failure
RestartSec=10
# Ajuste memória aqui (ex.: 2G, 4G, 6G)
ExecStart=/usr/bin/java -Xms2G -Xmx2G -jar server.jar nogui
SuccessExitStatus=143
TimeoutStopSec=20
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target
EOF

# Recarregue, habilite e inicie
sudo systemctl daemon-reload
sudo systemctl enable --now minecraft

# Acompanhe os logs
tail -n +1 /opt/minecraft/server/logs/latest.log || true
journalctl -u minecraft -f -n 50

5) Useful server.properties adjustments

The server.properties file controls online mode, view distance, the server MOTD and more. Edit it to match your needs. Lower distances reduce CPU and RAM usage.

If you use plugins and performance tweaks, consider forks like Paper or Purpur. They keep plugin compatibility and improve performance.

  • online-mode=true enforces official account verification.
  • view-distance and simulation-distance impact performance.
  • motd shows the message in the server list.
  • white-list=true restricts access to approved players.
# /opt/minecraft/server/server.properties (exemplo)
server-port=25565
online-mode=true
motd=Servidor Survival BR \u2013 boas vindas!
view-distance=8
simulation-distance=8
difficulty=normal
gamemode=survival
max-players=20
white-list=false
enable-command-block=false
spawn-protection=16
allow-nether=true
hardcore=false
max-world-size=29999984

6) Open ports, DNS and connection tests

Ensure port 25565 is open at every level: UFW, your cloud provider’s firewall and the router/NAT if applicable. In cloud environments, add an inbound TCP 25565 rule to the Security Group (AWS) or VPC Firewall (GCP).

Create an A record to point a domain or subdomain to your public IP so players can find the server more easily.

Test local listening and connectivity. If the port is not LISTENING, check service logs and the server.jar path.

  • On a home router, forward TCP 25565 to the server's internal IP.
  • In cloud, review source range (0.0.0.0/0) and restrict if you use IP whitelists.
  • DNS can take minutes to propagate.
# UFW (se ainda não tiver liberado)
sudo ufw allow 25565/tcp
sudo ufw status

# Verifique se está escutando localmente na 25565
sudo ss -tulpn | grep 25565 || true

# Teste DNS (substitua pelo seu domínio)
nslookup mc.seudominio.com || dig +short mc.seudominio.com

7) Backups, safe updates and automation

Keep regular backups of the world directory. Do NOT copy worlds while the server is writing: stop the service to avoid corruption. To update, replace server.jar and restart the service.

You can schedule daily backups with cron and keep a number of versions. Store backups on another machine or external storage for extra safety.

If you host in the cloud, monitor costs and scale resources as needed.

  • Stop the service before backups and updates.
  • Compress with tar.gz to save space.
  • Test restores periodically.
  • Consider disk snapshots if your provider supports them.
# Pare, compacte e reinicie (backup manual)
sudo systemctl stop minecraft
sudo mkdir -p /opt/minecraft/backups
sudo tar -czf /opt/minecraft/backups/mc-$(date +%F-%H%M).tar.gz -C /opt/minecraft server
sudo systemctl start minecraft

# Script simples de backup rotativo (mantém 7 arquivos)
sudo tee /usr/local/bin/backup-minecraft.sh > /dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
BKPDIR=/opt/minecraft/backups
SRCDIR=/opt/minecraft/server
mkdir -p "$BKPDIR"
systemctl stop minecraft
ARCHIVE="$BKPDIR/mc-$(date +%F-%H%M).tar.gz"
tar -czf "$ARCHIVE" -C /opt/minecraft server
systemctl start minecraft
# remove backups antigos, mantém 7
ls -1t "$BKPDIR"/mc-*.tar.gz | tail -n +8 | xargs -r rm -f
EOF
sudo chmod +x /usr/local/bin/backup-minecraft.sh

# Cron diário às 3h (executa como root)
( crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/backup-minecraft.sh" ) | sudo crontab -

8) How to confirm it worked and troubleshoot common issues

Check logs, port listening and external connections. Ask a friend to test with your IP or domain. Below are common symptoms and how to resolve them.

For availability monitoring and alerts, integrate system checks and Linux monitoring. This helps detect crashes and outages earlier.

  • journalctl shows Java errors, out-of-memory or invalid jar issues.
  • If 25565 is not LISTENING, review the systemd unit and the server.jar path.
  • If external connections fail, verify cloud firewall rules and router NAT.
Symptom Likely cause How to fix
Players can't connect from outside Port 25565 blocked in cloud/NAT Open 25565/TCP at the provider and set up port forwarding on the router
Server crashes on load Insufficient RAM or heavy plugins Lower view-distance, increase RAM or use an optimized fork like Paper
EULA message appears eula.txt still set to false Set eula=true after reading the terms and restart the service
High latency Network route or distant region Choose a region closer to players; avoid hosting on flaky Wi‑Fi
# Logs recentes do serviço
journalctl -u minecraft --since "15 minutes ago" -n 200 --no-pager

# Verifique escuta da porta
sudo ss -ltnp | grep 25565 || true

# Teste resolução DNS
nslookup mc.seudominio.com || dig +short mc.seudominio.com

Frequently asked questions

Which Java version should I use for a Minecraft server?

OpenJDK 17 is the most common choice for modern Minecraft Java Edition servers. Install and keep Java updated via your distribution’s package manager, and test the server after Java updates to confirm the server.jar and any plugins remain compatible. The guide shows installing OpenJDK 17 and verifying functionality on a 64-bit Linux system.

How much RAM do I need for the server?

It depends on player count, world complexity, redstone and plugins. Small servers often run fine with 2–4 GB of RAM. For more players, heavy redstone or many plugins, increase memory and reduce view-distance to save CPU and RAM. Monitor real usage and set -Xms/-Xmx in the systemd service, leaving headroom for the OS.

How do I change the default port 25565?

Edit server.properties (server-port=NUMBER) to change the TCP port, then update UFW, cloud security groups or router port forwarding to allow the new port. Restart the service and verify the server is LISTENING. Tell players to connect using host:port unless you configure SRV records; also update any DNS or NAT rules if needed.

Can I use a domain like play.yourdomain.com?

Yes. Create an A record that points a domain or subdomain to your server's public IP address. DNS propagation can take minutes. If you use a non-default port, players must connect with host:port unless you add an SRV record. The guide also recommends choosing a nearby cloud region and checking provider firewall rules when hosting in the cloud.

How do I safely update server.jar?

Stop the server service, back up the entire server directory, replace server.jar with the new file and restart the service. Check logs for errors and test the world. For setups with plugins, verify compatibility first in a test environment when possible to avoid breaking the live server or corrupting worlds.

How can I automate periodic restarts?

Use a systemd timer or a cron job to run systemctl restart minecraft during low-traffic periods and notify players in advance. Regular restarts can free memory and reduce some crashes, but they are not a substitute for proper configuration, performance tuning, or fixing underlying issues; monitor and adjust as needed.

Need help with Linux, automation or monitoring?

If you'd like assistance with hardening, backups, cloud migration or monitoring your server, talk to an expert to speed up setup and secure your configuration.

Talk about my server

See also