Minecraft server with tmux under ubuntu 16.04

This is an adaption of http://www.excogitation.org/setting-up-a-minecraft-server-using-systemd-under-ubuntu-15-10/
Above guide is good, but I prefer doing things a little different, for instance I prefer tmux instead of screen. Screen is a bit less user friendly, and attaching to a session started from systemd job is more problematic under screen

Install dependencies:

sudo apt-get install default-jre

Create a user for your minecraft server:

sudo adduser minecraft

switch to minecraft user

su minecraft

add server directory:

mkdir server
cd server

Download server, link can be found here: https://minecraft.net/download

wget https://s3.amazonaws.com/Minecraft.Download/versions/1.9.2/minecraft_server.1.9.2.jar
mv minecraft_server.1.9.2.jar minecraft_server.jar

Run minecraft once

java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

Accept eula:

nano eula.txt

change the eula line to this:


Log out from the minecraft user


Add systemd job file:

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

Add this:

Description=Minecraft Server


ExecStart=/usr/bin/tmux new-session -d -s mc-server /usr/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

ExecStop=/usr/bin/tmux send-keys -t mc-server 'say SERVER SHUTTING DOWN. Saving map...' C-m
ExecStop=/usr/bin/tmux send-keys -t mc-server 'save-all' C-m
ExecStop=/usr/bin/tmux send-keys -t mc-server 'stop' C-m
ExecStop=/bin/sleep 2


Enable the systemd job

sudo systemctl enable minecraft.service

Now you can start and stop the minecraft server with

sudo service minecraft start
sudo service minecraft stop

Comments are closed.