Install Minecraft Server on Ubuntu? We can help you.
Minecraft is one of the most popular games of all time. It is a sandbox video game where players explore infinite worlds and build different structures from simple houses to towering skyscrapers.
As part of our Server Management Services, we assist our customers with several Ubuntu queries.
Today, let us discuss how to install Minecraft Server on Ubuntu 20.04
Install Minecraft Server on Ubuntu 20.04?
Stuff
In this article, let us see 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 Techs recommend having 4GB of RAM as a minimum configuration for a typical setup.
In addition, install the packages required to build the mcrcon tool:
- 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:
We can verify the installation by printing the Java version:
- 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:
Since we do not set a password for this user login via SSH is not possible and cannot compromise.
- Install Minecraft on Ubuntu
Before we start with the installation process, we switch to the Minecraft user:
To create three new directories inside the user home directory we run:
- Download and Compile mcrcon
RCON is a protocol that allows us to connect to the Minecraft servers and execute commands. mcron can be used to connect to the Minecraft servers and execute commands. It is 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:
Once done, switch to the mcron directory and build the utility:
Then, verify that mcrcon has been successfully compiled by printing its version:
Our output will be like this:
- 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 Techs 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:
- Configure Minecraft Server
After the download, switch to the ~/server directory and start the Minecraft server:
For the first time, the server executes some operations, creates the server.properties and eula.txt files, and stops.
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:
Close and save the file.
Next, open the server.properties file and enable the rcon protocol and set the rcon password:
Locate the following and update their values, as shown below:
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.
- Create Systemd Unit File
Instead of manually starting Minecraft servers, we will create Systemd unit files 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:
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:
To start the Minecraft server we run:
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:
Finally, enable the Minecraft service to automatically start at boot time:
- Adjust Firewall
Ubuntu ships with a firewall configuration tool called UFW.
If the firewall is enabled on your system, you will need to open port 25565. We want to access Minecraft servers from outside our local network.
- Configure Backups
Moving ahead, let us create a backup shell script and cronjob to automatically backup the Minecraft server.
We switch to Minecraft:
Open the text editor and create the following file:
Then paste the following configuration:
Save the file and make the script executable:
Then, we create a cron job that will run once a day at a fixed time.
Open the crontab file:
Then, to run the backup script every day at 23:00, paste the following line:
- 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:
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 the installation? We'd be happy to assist you]
To conclude, we discussed how our Support Techs install a Minecraft server on Ubuntu 20.04 and set up a daily backup. We can now launch the Minecraft client, connect to the server and start Minecraft adventure.