Setting up a Minecraft server (often abbreviated as MCP server) on an Ubuntu server involves several steps. Here's a detailed guide to help you through the process:
Prerequisites
- Ubuntu Server: Ensure you have an Ubuntu server set up. This guide assumes you have root or sudo access.
- Java: Minecraft server requires Java to run.
Step-by-Step Guide
1. Update Your System
First, update your package lists and upgrade your system to ensure you have the latest software versions.
sudo apt update
sudo apt upgrade -y
2. Install Java
Minecraft server requires Java. You can install the OpenJDK package.
sudo apt install openjdk-17-jdk -y
Verify the installation:
java -version
3. Create a Directory for the Minecraft Server
Create a directory where you will store the Minecraft server files.
mkdir minecraft
cd minecraft
4. Download the Minecraft Server
Download the latest Minecraft server .jar file from the official Minecraft website. You can use wget to download it directly.
wget https://piston-meta.mojang.com/mc/asset/versions/latest/minecraft_server.1.18.2.jar
Replace 1.18.2 with the latest version number if necessary.
5. Accept the EULA
You need to accept the End User License Agreement (EULA) to run the server.
echo "eula=true" > eula.txt
6. Run the Minecraft Server
Run the server for the first time to generate the necessary configuration files.
java -Xmx1024M -Xms1024M -jar minecraft_server.1.18.2.jar nogui
This command allocates 1GB of RAM to the server. You can adjust the -Xmx and -Xms values based on your server’s available RAM.
7. Configure the Server (Optional)
After the initial run, the server will generate configuration files like server.properties. You can edit these files to configure your server settings.
nano server.properties
Make any desired changes and save the file.
8. Create a Systemd Service (Optional but Recommended)
To make managing the Minecraft server easier, you can create a systemd service.
Create a new service file:
sudo nano /etc/systemd/system/minecraft.service
Add the following content, adjusting the paths as necessary:
[Unit]
Description=Minecraft server
After=network.target
[Service]
User=yourusername
Group=yourusername
WorkingDirectory=/home/yourusername/minecraft
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.1.18.2.jar nogui
SuccessExitStatus=0 1
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl enable minecraft
sudo systemctl start minecraft
Check the status to ensure it’s running:
sudo systemctl status minecraft
9. Port Forwarding (If Behind a Router)
If your server is behind a router, you’ll need to forward port 25565 (the default Minecraft port) to your server’s local IP address. Consult your router’s documentation for instructions on how to do this.
Conclusion
You now have a Minecraft server running on your Ubuntu server. You can connect to it using the server’s IP address and the port you’ve configured. If you set up the systemd service, you can easily manage the server using systemctl commands.