Objective

The following article will describe a Minecraft server configuration procedure on Ubuntu 18.04 Bionic Beaver Linux

Operating System and Software Versions

  • Operating System: - Ubuntu 18.04
  • Software: - Minecraft Server 1.12.2 or higher

Requirements

Privileged access to to your Ubuntu 18.04 system will be required.

Difficulty

MEDIUM

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Instructions

Install Prerequisites

Let's start by installation of all prerequisites including the nmap command which we can later use for some basic troubleshooting purposes:
$ sudo apt update
$ sudo apt install wget screen default-jdk nmap 

Create Minecraft user

Next, we need to create a new user named minecraft. The Minecraft server will eventually run under this user:
$ sudo useradd -m -r -d /opt/minecraft minecraft

Install Minecraft Server

As you will see later, it is possible to run multiple instances of the Minecraft server on a single host. From this reason we will create a separate directory for each instance under the /opt/minecraft directory. Let's call our first instance survival:
$ sudo mkdir /opt/minecraft/survival
Once ready, download the java Minecraft server. Before you proceed, navigate your browser to the official Minecraft download page and update the below command to reflect the current Minecraft server version:
$ sudo wget -O /opt/minecraft/survival/minecraft_server.jar https://s3.amazonaws.com/Minecraft.Download/versions/1.12.2/minecraft_server.1.12.2.jar
Accept terms and conditions:
$ sudo bash -c "echo eula=true > /opt/minecraft/survival/eula.txt" 
Lastly, change the ownership of the /opt/minecraft/survival/ directory and of all files within:
$ sudo chown -R minecraft /opt/minecraft/survival/

SUBSCRIBE TO NEWSLETTER
Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Create Minecraft SystemD startup script

To be able to conveniently start the Minecraft server after the reboot use your favorite text editor eg. vi:
$ sudo vi /etc/systemd/system/minecraft@.service 
and create new /etc/systemd/system/minecraft@.service file with the following content:

[Unit]
Description=Minecraft Server: %i
After=network.target

[Service]
WorkingDirectory=/opt/minecraft/%i

User=minecraft
Group=minecraft

Restart=always

ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS. SAVING ALL MAPS..."\015'
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\015'


[Install]
WantedBy=multi-user.target
The above file serves as an example only. To increase RAM from 2GB to 4GB change:
FROM:
ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui
TO:
ExecStart=/usr/bin/screen -DmS mc-%i /usr/bin/java -Xmx4G -jar minecraft_server.jar nogui

Start Minecraft Server

Next, use the systemctl command to start your new Minecraft server:
$ sudo systemctl start minecraft@survival
Confirm that the new Minecraft server is up and running:
$ sudo systemctl status minecraft@survival

● This email address is being protected from spambots. You need JavaScript enabled to view it.
	 - Minecraft Server: survival
   Loaded: loaded (/etc/systemd/system/minecraft@.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-01-22 12:46:37 AEDT; 16s ago
 Main PID: 7751 (screen)
    Tasks: 21 (limit: 4915)
   CGroup: /system.slice/system-minecraft.slice/This email address is being protected from spambots. You need JavaScript enabled to view it.
           ├─7751 /usr/bin/SCREEN -DmS mc-survival /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui
           └─7757 /usr/bin/java -Xmx2G -jar minecraft_server.jar nogui

Jan 22 12:46:37 ubuntu systemd[1]: Started Minecraft Server: survival.
To make sure that the minecraft server starts after the reboot execute:
$ sudo systemctl enable minecraft@survival
If all went as planned you should be able now to use the nmap command to check for the default Minecraft port 25565:
$ nmap -p 25565 localhost

Starting Nmap 7.60 ( https://nmap.org ) 
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00054s latency).
Other addresses for localhost (not scanned): ::1

PORT      STATE SERVICE
25565/tcp open  minecraft

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
All done. To provision another Minecraft server instance on the same server continue reading the next section.


Provision new Minecraft server instance on the same host

The following linux commands will configure a new Minecraft server named linuxconfig on port 25566. See the below appendix for the additional server configurations to be implemented within/opt/minecraft/linuxconfig/server.properties. Using our existing systemd script to deploy another instance of Minecraft server is easy as:
$ sudo mkdir /opt/minecraft/linuxconfig
$ sudo cp /opt/minecraft/survival/minecraft_server.jar /opt/minecraft/linuxconfig/
$ sudo bash -c "echo eula=true > /opt/minecraft/linuxconfig/eula.txt" 
$ sudo bash -c "echo server-port=25566 > /opt/minecraft/linuxconfig/server.properties"
$ sudo chown -R minecraft /opt/minecraft/linuxconfig/
Enable Minecraft server to start after reboot and start the server:
$ sudo systemctl enable minecraft@linuxconfig
$ sudo systemctl start minecraft@linuxconfig
Lastly, check for status:
$ sudo systemctl status minecraft@linuxconfig

Appendix

Default minecraft server.properties settings:
max-tick-time=60000
generator-settings=
allow-nether=true
force-gamemode=false
gamemode=0
enable-query=false
player-idle-timeout=0
difficulty=1
spawn-monsters=true
op-permission-level=4
pvp=true
snooper-enabled=true
level-type=DEFAULT
hardcore=false
enable-command-block=false
max-players=20
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
server-port=25565
server-ip=
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=10
resource-pack=
spawn-animals=true
white-list=false
generate-structures=true
online-mode=true
max-build-height=256
level-seed=
prevent-proxy-connections=false
use-native-transport=true
motd=A Minecraft Server
enable-rcon=false
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.