Read in 7 minutes
last updated
How to Install Minecraft Server on CentOS 7

Minecraft is one of the most popular games of all time. It is a sandbox video game about placing blocks and going on adventures.
In this tutorial, we’ll go through the steps necessary to install and configure Minecraft Server on CentOS 7. We’ll use Systemd to run the Minecraft server and the mcrcon
utility for connecting to the running instance. We’ll also show you how to schedule automated server backups using a Cron job.
Prerequisites
The user you are logged in as must have sudo privileges to be able to install packages.
Install the packages required to build the mcrcon
tool:
sudo yum install git
sudo yum group install "Development Tools"
Installing Java Runtime Environment
Minecraft requires Java 8 or greater. Because the Minecraft Server doesn’t need a graphical user interface, we’ll install the headless version of the JRE. This version is more suitable for server applications since it has less dependencies and uses less system resources.
The installation of Java is pretty simple, just run:
sudo yum install java-1.8.0-openjdk-headless
Verify the installation by printing the java version:
java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Creating Minecraft User
Running services as Minecraft under the root user is not recommended for security reasons.
We’ll create a new system user and group minecraft
with home directory /opt/minecraft
that will run the Minecraft server:
sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft
We are not going to set password for this user. This is good security practice because this user will not be able to login via SSH. To change to the minecraft
user you’ll need to be logged in to the server as root or user with sudo privileges.
Installing Minecraft on CentOS
Before starting with the installation process, make sure you switch to minecraft
user.
sudo su - minecraft
Create three new directories inside the user home directory using the following command:
mkdir -p ~/{backups,tools,server}
- The
backups
directory will store your server backup. You can later synchronize this directory to your remote backup server. - The
tools
directory will be store themcrcon
client and the backup script. - The
server
directory will contain the actual Minecraft server and its data.
Downloading and Compiling mcrcon
RCON is a protocol that allows you to connect to the Minecraft servers and execute commands. mcron is RCON client built in C.
We’ll download the source code from GitHub and build the mcrcon
binary.
Start by navigating to the ~/tools
directory and clone the Tiiffi/mcrcon
repository from GitHub using the following command:
cd ~/tools && git clone https://github.com/Tiiffi/mcrcon.git
Once the repository is cloned, navigate to its directory:
cd ~/tools/mcrcon
Start the compilation of the mcrcon
utility by typing:
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c
When completed, test it by typing:
./mcrcon -h
The output will look something like this:
Usage: mcrcon [OPTIONS]... [COMMANDS]...
Sends rcon commands to minecraft server.
Option:
-h Prints usage.
-s Silent mode. Do not print data received from rcon.
-t Terminal mode. Acts as interactive terminal.
-p Rcon password. Default: "".
-H Host address or ip.
-P Port. Default: 25575.
-c Do not print colors. Disables bukkit color printing.
Individual commands must be separated with spaces.
Example:
mcrcon -c -H 192.168.1.42 -P 9999 -p password cmd1 "cmd2 with spaces"
minecraft rcon (mcrcon) 0.0.5.
Report bugs to tiiffi_at_gmail_dot_com.
Downloading Minecraft Server
There are several Minecraft server mods like Craftbukkit or Spigot that allows you to add features (plugins) on your server and further customize and tweak the server settings. In this tutorial we will install the latest Mojang’s official vanilla Minecraft server.
The latest Minecraft server’s Java archive file (JAR) is variable for download from the Minecraft download page.
At the time of writing, the latest version is 1.13.2
. Before continuing with the next step you should check the download page for a new version.
Run the following wget
command to download the Minecraft jar file in the ~/server
directory:
wget https://launcher.mojang.com/v1/objects/3737db93722a9e39eeada7c27e7aca28b144ffa7/server.jar -P ~/server
Configuring Minecraft Server
Navigate to the ~/server
directory and start the Minecraft server:
cd ~/server
java -Xmx1024M -Xms512M -d64 -jar server.jar nogui
When you start the server for the first time it executes some operations and creates the server.properties
and eula.txt
files and stops.
[14:33:16] [main/INFO]: Loaded 0 recipes
[14:33:16] [main/INFO]: Loaded 0 advancements
[14:33:16] [Server thread/INFO]: Starting minecraft server version 1.13.2
[14:33:16] [Server thread/INFO]: Loading properties
[14:33:16] [Server thread/WARN]: server.properties does not exist
[14:33:16] [Server thread/INFO]: Generating new properties file
[14:33:16] [Server thread/WARN]: Failed to load eula.txt
[14:33:16] [Server thread/INFO]: You need to agree to the EULA in order to run the server. Go to eula.txt for more info.
[14:33:16] [Server thread/INFO]: Stopping server
[14:33:16] [Server thread/INFO]: Saving worlds
[14:33:16] [Server Shutdown Thread/INFO]: Stopping server
[14:33:16] [Server Shutdown Thread/INFO]: Saving worlds
You’ll need to agree to the Minecraft EULA in order to run the server. Open the eula.txt
file and change eula=false
to eula=true
:
nano ~/server/eula.txt
#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Thu Dec 27 03:33:56 PST 2018
eula=true
Close and save the file.
Next, open the server.properties
file, enable the rcon protocol and set the rcon password. You will use this settings to connect to the Minecraft server with the mcrcon
tool.
nano ~/server/server.properties
rcon.port=23888
rcon.password=strong-password
enable-rcon=true
Do not forget to change the strong-password
to something more secure. Alternatively you can specify another port.
If you dont want to connect to the Minecraft server from remote locations make sure the rcon port is blocked by your firewall.
While here, you can also adjust the server’s default properties. For more information about the possible settings visit the server.properties page.
Creating Systemd Unit File
To run Minecraft as a service we will create a new Systemd unit file.
Switch back to your sudo user by typing exit
.
Open your text editor and create a file named minecraft.service
in the /etc/systemd/system/
:
sudo nano /etc/systemd/system/minecraft.service
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 -Xms512M -jar server.jar nogui --noconsole
ExecStop=/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 23888 -p strong-password stop
[Install]
WantedBy=multi-user.target
Modify the Xmx
and Xms
flags according to your server resources. The Xmx
flag defines the maximum memory allocation pool for a Java virtual machine (JVM), while Xms
defines the initial memory allocation pool. Also make sure that your are using the correct rcon
port and password.
Save and close the file and notify systemd that we created a new unit file:
sudo systemctl daemon-reload
Now you can start the Minecraft server by executing:
sudo systemctl start minecraft
The fist time you 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: disabled)
Active: active (running) since Sat 2019-01-19 14:35:52 UTC; 4s ago
Main PID: 17356 (java)
CGroup: /system.slice/minecraft.service
└─17356 /usr/bin/java -Xmx1024M -Xms512M -jar server.jar nogui --noconsole
Enable the Minecraft service to be automatically started at boot time:
sudo systemctl enable minecraft
Adjusting Firewall
If your server is protected by a firewall to access Minecraft server from the outside of your local network you need to open port 25565
:
sudo firewall-cmd --permanent --zone=public --add-port=25565/tcp
sudo firewall-cmd --reload
Configuring Backups
In this section we’ll create a backup script and cron job to automatically backup the Minecraft server.
Start by switching to minecraft
user:
sudo su - minecraft
Open your text editor and create the following file:
nano /opt/minecraft/tools/backup.sh
Paste the following configuration:
#!/bin/bash
function rcon {
/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 23888 -p strong-password "$1"
}
rcon "save-off"
rcon "save-all"
tar -cvpzf /opt/minecraft/backups/server-$(date +%F_%R).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 it executable:
chmod +x /opt/minecraft/tools/backup.sh
Open the crontab file and create a cron job that will run once in a day automatically at a fixed time:
crontab -e
We’ll run the backup script every day at 23:00h:
0 23 * * * /opt/minecraft/tools/backup.sh
Accessing Minecraft Console
To access the Minecraft Console you can use the mcrcon
utility.
The syntax is as follows, you need to specify the host, rcon port, rcon password and use the -t
switch that enables the mcrcon
terminal mode:
/opt/minecraft/tools/mcrcon/mcrcon -H 127.0.0.1 -P 23888 -p strong-password -t
Logged in. Type "Q" to quit!
>
If you are regularly connecting to the Minecraft console, instead of typing this long command you should create a bash alias.
Conclusion
You have successfully installed Minecraft server on your CentOS 7 system and setup a daily backup.
If you hit a problem or have feedback, leave a comment below.