Step-by-Step Guide: Installing Minecraft Server on Ubuntu 20.04 LTS

Minecraft is a highly popular open-world sandbox video game developed by Mojang Studios. It offers limitless creativity, allowing you to build anything imaginable with unlimited resources in its Creative mode. It features both online multiplayer and single-player modes, making it beloved globally. If you wish to play with friends, you can create your own Minecraft server.

This guide will walk you through setting up your own Minecraft server on Ubuntu 20.04 LTS.

Prerequisites

  • A server running Ubuntu 20.04 with at least 4 GB RAM.
  • Root password configured on your server.

Getting Started

To begin, update your system to the latest version using the following commands:

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

After updating, install the necessary dependencies with:

apt-get install git build-essential -y

Install Java

Since Minecraft is based in Java, the headless version of Java must be installed. Use the following command:

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

Verify the Java installation with:

java -version

Example output:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Install Minecraft Server

Create a separate user for Minecraft:

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

Switch to the Minecraft user:

su - minecraft

Create the necessary directories:

mkdir ~/backups ~/tools ~/server

Install mcrcon

Install mcrcon to manage communication with the Minecraft server:

Clone the repository:

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

Build mcrcon:

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

Verify the installation:

./mcrcon -v

Expected output:

mcrcon 0.7.1 (built: Jul  2 2020 07:44:45) - https://github.com/Tiiffi/mcrcon
Bug reports:
    tiiffi+mcrcon at gmail
    https://github.com/Tiiffi/mcrcon/issues/

Download and Configure Minecraft Server

Download Minecraft server:

wget https://launcher.mojang.com/v1/objects/a0d03225615ba897619220e256a266cb33a44b6b/server.jar -P ~/server

Start the server:

        cd ~/server
        java -Xmx1024M -Xms1024M -jar server.jar nogui

If you encounter an error relating to the EULA:

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

Agree to the EULA by editing the eula.txt file:

nano ~/server/eula.txt

Change:

eula=false

to:

eula=true

Edit server.properties to enable RCON:

nano ~/server/server.properties
rcon.password=your-password
enable-rcon=true 

Create a Systemd Unit File for Minecraft

Create a systemd service 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=/opt/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui
ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p your-password stop

[Install]
WantedBy=multi-user.target

Reload the systemd daemon:

systemctl daemon-reload

Start and enable the Minecraft service:

        systemctl start minecraft
        systemctl enable minecraft

Verify the service status:

systemctl status minecraft

Sample output:

? minecraft.service - Minecraft Server
     Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-07-02 08:05:24 UTC; 1min 0s ago
   Main PID: 11704 (java)
      Tasks: 30 (limit: 4691)
     Memory: 1.0G
     CGroup: /system.slice/minecraft.service
             ??11704 /usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui

Verify the server is listening on port 25575:

netstat -pnltu | grep 25575

Sample output:

tcp6       0      0 :::25575                :::*                    LISTEN      10584/java

Access Minecraft Console

Use mcrcon to access the Minecraft console:

/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p your-password -t

Successful connection output:

Logged in. Type 'quit' or 'exit' to quit.
>

Conclusion

You’ve successfully installed a Minecraft server on Ubuntu 20.04. Feel free to ask any questions or seek further clarification as needed. Happy gaming!

FAQ

Q: What are the minimum system requirements for the Minecraft server?
A: The server should run Ubuntu 20.04 with at least 4 GB of RAM.
Q: How do I enable the Minecraft server to start at boot?
A: Enable the server using the command systemctl enable minecraft.
Q: How can I modify the server settings?
A: Edit the server.properties file located in the /opt/minecraft/server directory to adjust server settings.
Q: How do I connect to my new Minecraft server?
A: Use a Minecraft client to connect to your server’s IP address on port 25575.
Q: Can I install mods on this server?
A: Yes, you can install mods by placing them in the /opt/minecraft/server/mods directory. Make sure the mod is compatible with your server version.