
How to Set Up a Minecraft Server on Ubuntu Server (Headless)
This guide assumes you have a fresh installation of Ubuntu Server (LTS recommended) and basic command-line knowledge.
Prerequisites:
- Ubuntu Server: A running instance of Ubuntu Server (e.g., 22.04 LTS or newer).
- SSH Access: (Optional, but recommended) Access your server via SSH from another computer.
- Sufficient Hardware:
- CPU: At least 2-4 cores (more for many players/heavy mods).
- RAM: Minimum 4GB (8GB+ recommended for performance and future expansion).
- Storage: 20GB+ SSD (SSD is highly recommended for performance).
- Network: Stable internet connection with good upload speeds.
Step 1: Update Your System
It’s always a good practice to update your server packages to the latest versions.
Bash
sudo apt update
sudo apt upgrade -y
Step 2: Install Java
Minecraft servers require Java to run. OpenJDK is the recommended choice.
Bash
sudo apt install openjdk-17-jre-headless -y
- Note: Minecraft versions have specific Java requirements.
- Minecraft 1.17+ requires Java 16 or newer.
- Minecraft 1.18+ requires Java 17 or newer.
- Minecraft 1.20+ (current) typically uses Java 17 or Java 21. Java 17 is a safe bet for most current versions.
Verify Java installation:
Bash
java -version
You should see output similar to openjdk version "17.0.X"
.
Step 3: Create a Minecraft Server User (Recommended)
Running the server as a dedicated, non-root user enhances security.
Bash
sudo adduser minecraft
sudo usermod -aG sudo minecraft # Optional: Grant sudo access if needed for user, but generally avoid for security
Switch to the minecraft
user:
Bash
su - minecraft
From now on, you’ll be operating as the minecraft
user unless specified.
Step 4: Create Server Directory and Download Minecraft Server JAR
Create a dedicated directory for your server files.
Bash
mkdir minecraft_server
cd minecraft_server
Now, download the official Minecraft server JAR file. You can find the download link on the official Minecraft website (minecraft.net/download/server). Replace YOUR_MINECRAFT_VERSION.jar
with the actual file name.
Example for Minecraft 1.20.6:
Bash
wget https://piston-data.mojang.com/v1/objects/141077736f87532EEF311f938c928b57BCb97956/server.jar
- Tip: Always check the official Minecraft website for the latest
server.jar
download URL.
Step 5: Accept the EULA (End User License Agreement)
The first time you try to run the server, it will fail and create an eula.txt
file. You must accept the EULA to proceed.
-
Attempt to run the server (this will fail and create eula.txt):
Bash
java -Xmx1024M -Xms1024M -jar server.jar nogui
(You can press
Ctrl+C
after you see the EULA message to stop it.) -
Edit the EULA file:
Bash
nano eula.txt
Change
eula=false
toeula=true
. -
Save and exit Nano: Press
Ctrl+O
, thenEnter
, thenCtrl+X
.
Step 6: Configure and Run the Minecraft Server
Now you can run the server with your desired memory allocation. The -Xmx
and -Xms
flags define the maximum and initial memory allocation for the Java Virtual Machine (JVM).
Bash
java -Xmx4G -Xms4G -jar server.jar nogui
- Explanation:
-Xmx4G
: Sets the maximum RAM to 4 Gigabytes.-Xms4G
: Sets the initial RAM to 4 Gigabytes.server.jar
: The name of your Minecraft server JAR file.nogui
: Runs the server without a graphical user interface (essential for a headless server).
The server will start generating the world. This can take a few minutes. Once it says Done!
, your server is running.
To stop the server: Type stop
in the console and press Enter
. This ensures a clean shutdown and saves the world data.
Step 7: Keep the Server Running in the Background (Using screen
)
If you close your SSH session, the server will stop. To keep it running, use a terminal multiplexer like screen
.
-
Install
screen
:Bash
sudo apt install screen -y
(You might need to
exit
theminecraft
user andsudo apt install screen -y
as your main user, thensu - minecraft
back). -
Start a new
screen
session:Bash
screen -S minecraft_server
You’ll now be inside a new
screen
session. -
Run your Minecraft server command inside the
screen
session:Bash
java -Xmx4G -Xms4G -jar server.jar nogui
-
Detach from the
screen
session (server keeps running): PressCtrl+A
, thenD
. You’ll see a message like[detached from ...]
and return to your main terminal. -
To reattach to the
screen
session (to see the server console):Bash
screen -r minecraft_server
-
To stop the server (from within the
screen
session): Typestop
and pressEnter
. Then, you can typeexit
to close thescreen
session.
Step 8: Configure Firewall (UFW)
You need to open the Minecraft server port (default 25565) in your server’s firewall (UFW – Uncomplicated Firewall).
-
Install UFW (if not already installed):
Bash
sudo apt install ufw -y
-
Allow SSH (so you don’t lock yourself out):
Bash
sudo ufw allow OpenSSH
-
Allow Minecraft server port:
Bash
sudo ufw allow 25565/tcp
-
Enable UFW:
Bash
sudo ufw enable
Confirm with
y
andEnter
. -
Check UFW status:
Bash
sudo ufw status
You should see
25565/tcp
andOpenSSH
listed asALLOW Anywhere
.
Step 9: Port Forwarding on Your Router
This is the most crucial step for allowing external players to connect. You need to configure your home router to forward incoming connections on port 25565 (or whatever port you set in server.properties
) to your Ubuntu server’s local IP address.
-
Find your server’s local IP address:
Bash
ip a
Look for the IP address next to
inet
under your network interface (e.g.,eth0
orenpXsY
). It will typically be something like192.168.1.X
or10.0.0.X
. -
Access your router’s administration page: Open a web browser and type in your router’s default gateway IP address (often
192.168.1.1
or192.168.0.1
). Log in with your router’s credentials. -
Locate “Port Forwarding” settings: This varies greatly between router models. Look under sections like “NAT,” “Virtual Servers,” “Firewall,” or “Advanced Settings.”
-
Create a new port forwarding rule:
- External Port / Port Range:
25565
- Internal Port:
25565
- Internal IP Address: Your Ubuntu server’s local IP address (e.g.,
192.168.1.100
). - Protocol:
TCP
(sometimesTCP/UDP
orBoth
is an option,TCP
is sufficient for Minecraft). - Enable/Save: Apply the changes.
- External Port / Port Range:
Step 10: Connect to Your Server!
- Find your public IP address: Go to a website like
whatismyipaddress.com
from a browser on any computer to find your home’s public IP address. - Launch Minecraft: In the Minecraft game client, click “Multiplayer.”
- Add Server:
- Server Name: (Anything you like, e.g., “My Awesome Server”)
- Server Address: Your public IP address (e.g.,
123.45.67.89
).
- Join Server!
Optional: Customize server.properties
You can stop the server (stop
command in the screen
session), then edit the server.properties
file to customize your server.
Bash
nano server.properties
Some common settings you might want to change:
motd=A Minecraft Server
(Message of the Day – what players see in the server list)gamemode=survival
(survival, creative, adventure, spectator)difficulty=easy
(peaceful, easy, normal, hard)max-players=20
(maximum number of players)online-mode=true
(set tofalse
to allow cracked clients, NOT RECOMMENDED as it bypasses Mojang’s authentication and offers no player security)level-name=world
(name of the world folder)allow-flight=true
(allows creative flight)
Save changes (Ctrl+O
, Enter
, Ctrl+X
) and restart the server.
Troubleshooting Tips:
- Cannot connect:
- Check firewall (UFW) on the server.
- Verify port forwarding on your router.
- Ensure the Minecraft server is actually running.
- Double-check your public IP address.
- Restart your router and server.
- Server Lag:
- Increase RAM allocated to the server (
-Xmx
and-Xms
flags). - Consider using PaperMC or Purpur instead of Vanilla
server.jar
for better performance. - Reduce view distance in
server.properties
. - Check server logs for errors or warnings.
- Increase RAM allocated to the server (
- Java Version: Ensure your Java version matches the Minecraft server’s requirements.
Enjoy your self-hosted Minecraft server!