×


Install Minecraft Server on Ubuntu 20.04

Minecraft is one of the most popular games of all time. 

It is a sandbox video game where you can explore randomly generated worlds and build amazing things from the simplest of homes to the grandest of castles. 

Ubuntu 20.04 Focal Fossa is a top choice for hosting a Minecraft server, as Linux is known for its stability when running servers and Ubuntu is known for its ease of use.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu related Software Installation tasks.

In this context, we shall look into how to install Minecraft Server on Ubuntu 20.04.


How to Install Minecraft Server on Ubuntu 20.04?

Here, you will learn how to make a Minecraft Server on Ubuntu 20.04 and how to create a cronjob that performs regular server backups.

We use Systemd to run the Minecraft server and the mcrcon utility to connect to the running instance.

In order to begin our Support Experts recommend having 4GB of RAM as a minimum configuration for a typical setup.

In addition, install the packages required to build the mcrcon tool by running the commands given below:

$ sudo apt update
$ sudo apt install git build-essential

Then follow the steps below to set up Minecraft Server on Ubuntu.


1. Install Java Runtime Environment

Since Minecraft requires Java 8 or higher and does not need a graphical user interface, so let us install the headless version of Java.

We run the following command to install the headless OpenJRE 11 package:

$ sudo apt install openjdk-11-jre-headless

We can verify the installation by printing the Java version:

$ java -version
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)


2. Create Minecraft User

For security reasons, we should not run Minecraft under the root user. 

We will create a new system user and group with a home directory /opt/minecraft with minimum necessary permissions to run the Minecraft server:

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

Since we do not set a password for this user login via SSH is not possible and cannot compromise.


3. Install Minecraft on Ubuntu

Before we start with the installation process, we switch to the Minecraft user:

$ sudo su – minecraft

To create three new directories inside the user home directory we run:

$ mkdir -p ~/{backups,tools,server}


4. Download and Compile mcrcon

RCON is a protocol that allows us to connect to the Minecraft servers and execute commands. mcron is an RCON client written in C.

We can download the source code from GitHub and build the mcrcon binary.

Clone the Tiiffi/mcrcon repository from GitHub to the ~/tools/mcron directory:

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

Once done, switch to the mcron directory and build the utility:

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

Then, verify that mcrcon has been successfully compiled by printing its version:

$ ./mcrcon -v

Our output will be like this:

mcrcon 0.7.1 (built: Jun 23 2020 15:49:44) – https://github.com/Tiiffi/mcrcon
Bug reports:
tiiffi+mcrcon at gmail
https://github.com/Tiiffi/mcrcon/issues/


5. Download Minecraft Server

Craftbukkit or Spigot is Minecraft servers that allow us to add features (plugins) on our server and further customize and tweak the server settings.

However, our Support Experts will install the latest Mojang’s official vanilla Minecraft server.

We can get the download link of the latest Minecraft server’s Java archive file (JAR) from the Minecraft download page.

We download the jar file in the ~/server directory with wget:

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


6. Configure Minecraft Server

After the download, switch to the ~/server directory and start the Minecraft server:

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

For the first time, the server executes some operations, creates the server.properties and eula.txt files, and stops.

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

As indicated, to run the server, we need to agree to the Minecraft EULA. 

Open the eula.txt file and change eula=false to eula=true:

$ nano ~/server/eula.txt
eula=true

Close and save the file.


Next, open the server.properties file and enable the rcon protocol and set the rcon password:

$ nano ~/server/server.properties

Locate the following and update their values, as shown below:

rcon.port=25575
rcon.password=strong-password
enable-rcon=true

Make sure to change the strong-password to something more secure. 

If we do not want to connect to the Minecraft server from remote locations, we have to block the rcon port by the firewall.


7. Create Systemd Unit File

Instead of manually starting the Minecraft server, we will create a Systemd unit file and run Minecraft as a service.

For that, we need to switch back to sudo user by typing exit.

Open the text editor and create the file minecraft.service in the /etc/systemd/system/ directory:

$ sudo nano /etc/systemd/system/minecraft.service

Then paste 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 strong-password stop
[Install]
WantedBy=multi-user.target


Modify the Xmx and Xms flags according to our server resources. Also, make sure to use the correct rcon port and password.

Eventually, save the file and reload the systemd manager configuration:

$ sudo systemctl daemon-reload

To start the Minecraft server we run:

$ sudo systemctl start minecraft

The first time we start the service, it will generate several configuration files and directories, including the Minecraft world.


Check the service status with the following command:

$ sudo systemctl status minecraft
● minecraft.service – Minecraft Server
Loaded: loaded (/etc/systemd/system/minecraft.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2020-06-23 17:48:44 UTC; 8s ago
Main PID: 1338035 (java)
Tasks: 15 (limit: 1074)
Memory: 465.3M
CGroup: /system.slice/minecraft.service
└─1338035 /usr/bin/java -Xmx1024M -Xms1024M -jar server.jar nogui

Finally, enable the Minecraft service to automatically start at boot time:

$ sudo systemctl enable minecraft

8. Adjust Firewall

Ubuntu ships with a firewall configuration tool called UFW.

We need to open port 25565 if the firewall is enabled on our system and want to access the Minecraft server from the outside of our local network:

$ sudo ufw allow 25565/tcp

9. Configure Backups

Moving ahead, let us create a backup shell script and cronjob to automatically backup the Minecraft server.

We switch to Minecraft:

$ sudo su – minecraft

Open the text editor and create the following file:

$ nano /opt/minecraft/tools/backup.sh

Then paste the following configuration:

#!/bin/bash
function rcon {
/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password “$1”
}
rcon “save-off”
rcon “save-all”
tar -cvpzf /opt/minecraft/backups/server-$(date +%F-%H-%M).tar.gz /opt/minecraft/server
rcon “save-on”


## Delete older backups

find /opt/minecraft/backups/ -type f -mtime +7 -name ‘*.gz’ -delete

Save the file and make the script executable:

$ chmod +x /opt/minecraft/tools/backup.sh

Then, we create a cron job that will run once a day at a fixed time.

Open the crontab file:

$ crontab -e

Then, to run the backup script every day at 23:00, paste the following line:

0 23 * * * /opt/minecraft/tools/backup.sh

10. Access Minecraft Console

To access the Minecraft Console, we use the mcrcon utility. We need to specify the host, rcon port, rcon password and use the -t switch which enables the mcrcon terminal mode:

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

Output:

Logged in. Type “Q” to quit!
>

While accessing the Minecraft Console from a remote location, make sure the rcon port is not blocked.

If we are regularly connecting to the Minecraft console, instead of typing this long command, we can create a bash alias.


[Stuck with Minecraft Server installation? We'd be happy to assist you. ]


Conclusion

This article will guide you on how to install a Minecraft server on #Ubuntu 20.04 and set up a daily backup. You can now launch the Minecraft client, connect to the server and start Minecraft adventure. 

Setting up a #Minecraft server on #Linux (Ubuntu 12.04) is a fairly easy task on the command line.

Of the previously given ports, the only one I want you to memorize is 25565, because that is Minecraft's default port number. What we want to do is forward inbound traffic on port 25565 to our Minecraft server that's located on the private internal network.

Process of Setting up Minecraft Server on Ubuntu:

1. Create New Minecraft User. Add the new “minecraftuser” to the “sudo” group.

2. Add Minecraft User To Sudo Group.

3. Switch To Minecraft User.

4. Install wget Package.

5. Install Java OpenJDK package.

6. Check Installed Java Version.

7. Install Screen Package.

8. Create A Minecraft Directory.


To Install #Steam from Ubuntu package repository :

i. Confirm that the multiverse Ubuntu repository is enabled: $ sudo add-apt-repository multiverse $ sudo apt update.

ii. Install Steam package: $ sudo apt install steam.

iii. Use your desktop menu to start Steam or alternatively execute the following command: $ steam.