Minecraft is one of the most popular sandbox video games that has sold over 100 million copies worldwide. It allows any users to crafting and Minecrafting together in multiplayer worlds. On a public Minecraft server, players can collaborate to make new bigger things. However, you can not control players. In this case, you can set up your own Minecraft server to use your admin powers and control each and every player.Â
This post will explain how to set up the Minecraft server on Ubuntu 20.04.
Install Java JDK
Minecraft is a Java-based application. So Java JDK must be installed on your server. If not installed, you can install it using the following command:
apt-get install openjdk-11-jre-headless git build-essential -y
Once Java is installed, verify the Java installation using the following command:
java -version
You will get the following output:
openjdk version "11.0.13" 2021-10-19 OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
Install and Configure Minecraft
Before starting, it is recommended to create a dedicated user to run Minecraft. You can create it using the following command:
useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft
Next, switch the user to Minecraft and create the necessary directory for Minecraft:
su - minecraft mkdir -p ~/{backups,tools,server}
Next, you will need to download and compile RCON to connect to Minecraft server.
First, download the RCON using the following command:
git clone https://github.com/Tiiffi/mcrcon.git ~/tools/mcrcon
Next, compile it using the following command:
cd ~/tools/mcrcon gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
Next, verify the RCON version using the following command:
./mcrcon -v
You will get the following output:
mcrcon 0.7.2 (built: Mar 3 2022 08:28:12) - https://github.com/Tiiffi/mcrcon Bug reports: tiiffi+mcrcon at gmail https://github.com/Tiiffi/mcrcon/issues/
Next, download the latest version of the Minecraft JAR file to the ~/server directory:
wget https://launcher.mojang.com/v1/objects/a0d03225615ba897619220e256a266cb33a44b6b/server.jar -P ~/server Next, change the directory to ~/server and start the Minecraft server using the following command: cd ~/server java -Xmx1024M -Xms1024M -jar server.jar nogui
You will get the following error:
[08:28:59] [main/ERROR]: Failed to load properties from file: server.properties [08:28:59] [main/WARN]: Failed to load eula.txt [08:28:59] [main/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
As you can see, you will need to agree to the Minecraft EULA.
To do so, edit the eula.txt file:
nano ~/server/eula.txt
Change the following line:
eula=true
Save and close the file, then edit the server.properties file:
nano ~/server/server.properties
Change the following lines:
rcon.port=25575 rcon.password=password enable-rcon=true
Save and close the file then exit from the Minecraft user with the following command:
exit
Create a Systemd Service File for Minecraft
Next, you will need to create a systemd service file to manage the Minecraft service. You can create it with the following command:
nano /etc/systemd/system/minecraft.service
Add the following lines:
[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 strong-password stop [Install] WantedBy=multi-user.target
Save and close the file, then reload the systemd daemon to apply the changes:
systemctl daemon-reload
Next, start and enable the Minecraft service with the following command:
systemctl start minecraft systemctl enable minecraft
You can now check the status of Minecraft using the following command:
systemctl status minecraft
You will get the following output:
minecraft.service - Minecraft Server      Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)      Active: active (running) since Thu 2022-03-03 08:31:40 UTC; 11s ago    Main PID: 12485 (java)       Tasks: 15 (limit: 2348)      Memory: 500.8M      CGroup: /system.slice/minecraft.service              └─12485 /usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui Mar 03 08:31:40 ubuntu2004 systemd[1]: Started Minecraft Server. Mar 03 08:31:50 ubuntu2004 java[12485]: [08:31:50] [main/INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://> Mar 03 08:31:51 ubuntu2004 java[12485]: [08:31:51] [main/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] w> Mar 03 08:31:51 ubuntu2004 java[12485]: [08:31:51] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] > Mar 03 08:31:51 ubuntu2004 java[12485]: [08:31:51] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with> Mar 03 08:31:51 ubuntu2004 java[12485]: [08:31:51] [main/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] w> Mar 03 08:31:51 ubuntu2004 java[12485]: [08:31:51] [main/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targ> Mar 03 08:31:51 ubuntu2004 java[12485]: [08:31:51] [main/INFO]: Reloading ResourceManager: Default
At this point, Minecraft service is started and listening on port 25575. You can check it with the following command:
ss -antpl | grep java
You will get the following output:
LISTENÂ Â 0 Â Â Â Â 50 Â Â Â Â Â Â Â Â Â Â Â *:25575Â Â Â Â Â Â Â Â Â *:*Â Â Â Â users:(("java",pid=12485,fd=26))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LISTENÂ Â 0 Â Â Â Â 4096 Â Â Â Â Â Â Â Â Â Â *:25565Â Â Â Â Â Â Â Â Â *:*Â Â Â Â users:(("java",pid=12485,fd=17))
Verify Minecraft Connectivity
At this point, the Minecraft server is installed and configured. Now, you will need to verify whether it is accessible or not. You can verify it using the mcrcon command-line utility. The mcrcon is an RCON client written in C that allows us to connect to the Minecraft servers and execute commands.
/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p password -t
Once you are connected, you will get the following output:
Logged in. Type 'Q' or press Ctrl-D / Ctrl-C to disconnect. >
Conclusion
Congratulations! you have successfully installed the Minecraft server on Ubuntu 20.04 server. You can now launch the Minecraft client, connect to the server and start Minecraft adventure.
Also Read: The Future Of Virtual Reality Gaming