There is a point to this story, but it has temporarily escaped my mind...
Contact Me MyFaceBook MyLinkedIn MyGitHub MyTwitter

Install Minecraft on Linux Server

First, make sure that all of the latest patches are installed

sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot

Install Java

Create a directory to store Minecraft

sudo mkdir /opt
cd /opt
sudo mkdir minecraft

Download Minecraft

cd /opt/minecraft

sudo wget https://s3.amazonaws.com/Minecraft.Download/versions/1.13.2/minecraft_server.1.13.2.jar

if [ -h minecraft_server.jar ]; then
    sudo rm -f minecraft_server.jar
fi

sudo ln -s minecraft_server.1.13.2.jar minecraft_server.jar

Start the server to generate all of the supporting files

cd /opt/minecraft
sudo chmod o+w /opt/minecraft
java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui
# After the server startup is "done", stop the server by pressing Ctrl-C
sudo chmod o-w /opt/minecraft

Create a user for Minecraft to run under

sudo useradd minecraft

Make sure that the minecraft user owns all of the files…

sudo chown -R minecraft:minecraft /opt/minecraft

I also like to have plugins on my server so I use Spigot:

cd /tmp
wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
 
java -jar BuildTools.jar --rev 1.13.2
 
sudo mv craftbukkit-1.13.2.jar spigot-1.13.2.jar /opt/minecraft/
 
cd /opt/minecraft
 
if [ -h spigot.jar ]; then
    sudo rm -f spigot.jar
fi
 
sudo ln -s spigot-1.13.2.jar spigot.jar
 
if [ -h craftbukkit.jar ]; then
    sudo rm -f craftbukkit.jar
fi
 
sudo ln -s craftbukkit-1.13.2.jar craftbukkit.jar 

Configure a startup script

Upstart (Ubuntu prior to 15.04)

cat > /tmp/minecraft.conf << EOF
# description "start and stop the minecraft-server"

chdir /opt/minecraft

exec su -s /bin/sh -c 'exec "\$0" "\$@"' minecraft -- \
    /usr/bin/java -Xms1024M -Xmx1024M -jar minecraft_server.jar nogui > /dev/null

start on runlevel [2345]
stop on runlevel [^2345]

EOF

sudo mv /tmp/minecraft.conf /etc/init/
sudo chown root:root /etc/init/minecraft.conf

systemd (Ubuntu 15.04 and after)

cat > /tmp/minecraft.service << EOF
[Unit]
Description=Minecraft Server
Documentation=

Wants=network.target
After=network.target

[Service]
User=minecraft
Group=minecraft
KillMode=process
SuccessExitStatus=0 1 143

ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
PrivateTmp=true
ReadWriteDirectories=/opt/minecraft
WorkingDirectory=/opt/minecraft
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui

[Install]
WantedBy=multi-user.target
EOF

sudo mv /tmp/minecraft.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/minecraft.service

sudo systemctl enable minecraft.service

Start Minecraft Service

sudo service minecraft start
Copyright © 2019 by Julian Easterling. SOME RIGHTS RESERVED.
Privacy Policy              Terms of Use             


Creative Commons License
Except where otherwise noted, content on this site is
licensed under a Creative Common Attribution-Share Alike 4.0 International License.


All of the opinions expressed on this website are those of Julian Easterling and
do not represent the views of any of my current and previous clients or employers in any way.

If you notice an error on the site or content that has not been properly attributed, bring
it to my attention using the contact page and I will endeavor to fix it as soon as I can.

I accept no responsibility or liability for any damages incurred by following any of
my advice or by using any of the information on my site or of those sites that I link to.