Step-by-Step Guide to Setting Up a Minecraft Server on Ubuntu

Minecraft, created by Microsoft Studios, ranks among the world’s most beloved games. It’s a sandbox video game that allows players to construct anything imaginable and explore vast 3D worlds. Minecraft offers both online multiplayer and single-player modes and is available across Linux, macOS, and Windows platforms.

This guide outlines the steps necessary to install a Minecraft server on an Ubuntu 18.04 server.

Requirements

  • An Ubuntu 18.04 server.
  • Root access to the server.

Getting Started

First, ensure your system is up-to-date by executing the following commands:

apt-get update -y
apt-get upgrade -y

After updating, reboot the server to apply the changes. Next, you’ll need to install some essential packages. Execute the following command:

apt-get install git build-essential -y

Install Java

Minecraft relies on Java, so you must install the Java Development Kit (JDK) or Java Runtime Environment (JRE). Use this command to install Java:

apt-get install openjdk-8-jre-headless -y

Verify the installation with:

java -version

Expected output should be similar to:

openjdk version "1.8.0_222"OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Install and Configure Minecraft Server

Create a user specifically for running the Minecraft server:

useradd -r -m -U -d /home/minecraft -s /bin/bash minecraft

Switch to the new Minecraft user:

su - minecraft

Create directories required for Minecraft:

mkdir backups tools server

Navigate to the ~/tools directory and clone mcrcon from its Git repository:

cd ~/tools
git clone https://github.com/Tiiffi/mcrcon.git

Compile mcrcon:

cd mcrcon
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

Expected output during compilation:

mcrcon.c: In function ‘get_line’:mcrcon.c:752:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  (void) fgets(buffer, bsize, stdin);

Now, download the official Minecraft server jar from Mojang:

cd ~/server
wget https://launcher.mojang.com/v1/objects/3dc3d84a581f14691199cf6831b71ed1296a9fdf/server.jar

Start your Minecraft server:

java -Xmx1024M -Xms512M -jar server.jar nogui

You should encounter this message:

[06:00:45] [main/ERROR]: Failed to load properties from file: server.properties[06:00:48] [main/WARN]: Failed to load eula.txt [06:00:48] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.

To agree to the EULA, edit the eula.txt file:

nano eula.txt

Change:

eula=true

Save the changes and close the file. Proceed to modify the server.properties file to enable RCON and set a password:

nano server.properties

Adjust these settings:

rcon.port=25575rcon.password=admin@123enable-rcon=true

After saving the file, exit the Minecraft user with:

exit

Create a Systemd Service File for Minecraft

Create a systemd service file to manage the Minecraft server:

nano /etc/systemd/system/minecraft.service

Add the following configuration:

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

[Service]
User=minecraft
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/home/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui
ExecStop=/home/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p admin@123 stop

[Install]
WantedBy=multi-user.target

Save the file, then reload the systemd daemon:

systemctl daemon-reload

Start the Minecraft server and enable it to start on reboot:

systemctl start minecraft
systemctl enable minecraft

Check the server status:

systemctl status minecraft

The output should resemble:

? minecraft.service - Minecraft Server
   Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-10-07 06:33:32 UTC; 6s ago
 Main PID: 4318 (java)
    Tasks: 34 (limit: 4915)
   CGroup: /system.slice/minecraft.service
           ??4318 /usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui

Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Loading properties
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Default game type: SURVIVAL
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Generating keypair
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Starting Minecraft server on *:25565
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Using epoll channel type
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Preparing level "world"
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Found new data pack vanilla, loading it automatically
Oct 07 06:33:37 ubuntu1804 java[4318]: [06:33:37] [Server thread/INFO]: Reloading ResourceManager: Default
Oct 07 06:33:38 ubuntu1804 java[4318]: [06:33:38] [Server thread/INFO]: Loaded 6 recipes
Oct 07 06:33:38 ubuntu1804 java[4318]: [06:33:38] [Server thread/INFO]: Loaded 811 advancements

Test Minecraft

Your Minecraft server is now ready. Test the connection using mcrcon:

/home/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p admin@123 -t

Upon connection, you should see:

Logged in. Type "Q" to quit!
>

Great job! You’ve successfully installed and configured a Minecraft server on an Ubuntu 18.04 system. For further questions, feel free to reach out.

FAQ

1. Do I need previous Linux administration experience to set up a Minecraft server?

While some familiarity with the Linux command line is beneficial, this guide provides step-by-step instructions suitable for beginners.

2. Can I change the server settings after installation?

Yes, you can edit the server.properties file located in the Minecraft server directory to adjust settings like game mode, difficulty, and more.

3. Is it necessary to run the Minecraft server as a separate user?

Running the server as a separate user enhances security by isolating server processes from the rest of the system.

4. How do I update the Minecraft server to the latest version?

To update, download the latest server.jar from the official Minecraft website and replace the existing jar in the server directory with this new file.

5. What should I do if the server crashes?

Check logs located in the server directory for any error messages. Ensure your system has adequate resources (memory, CPU) to run the server smoothly.