Minecraft Server Configuration
In this post, we will see how can install our own Minecraft server on our Ubuntu (or any Debian based) system.
By installing our own Minecraft server, and exposing it to the outside world, we can play with our friends online in a Survival or a Creative world.
We also have full control off the game, and a lot of customization and modding abilities.
Install Java
And other needed software:
sudo apt install default-jdk wget screen
Create a minecraft user
useradd minecraft
Install minecraft server
Each server instance we run will need its own directory under the /opt/minecraft
directory.
For this first server instance, let’s call it survival
and create the following directory
sudo mkdir /opt/minecraft/survival
Download minecraft server
Visit and copy link url of latest version of minecraft_server.1.*.jar
:
wget https://launcher.mojang.com/v1/objects/1b557e7b033b583cd9f66746b7a9ab1ec1673ced/server.jar
Rename .jar
Rename .jar
to the latest version names:
mv server.jar minecraft_server.1.6.5.jar
Accept terms and conditions
sudo bash -c "echo eula=true > /opt/minecraft/survival/eula.txt"
Give minecraft user ownership
sudo chown -R minecraft:minecraft /opt/minecraft/survival/
Start server
Create startup script
Create a start.sh
script and write the following:
#!/bin/sh
java -Xmx4096M -Xms2048M -jar minecraft_server.1.16.5.jar nogui
Xmx
Maximum RAM usageXms
RAM usage on startup
Make it executable
chmod +x *.sh
Run server to test
./start.sh
Start server with screen
Open a screen session
screen -S minecraft_server
Start server in the session
./start.sh
Detach from session
Hold down Ctrl
and hit A
and D
in the session.
Reattach to session
screen -r minecraft_server
Make server a systemd service
Create template systemd script
Create a systemd template script, can be used for other server instances:
vim /etc/systemd/system/minecraft@.service
Paste the following content in the new file
[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 ./start.sh
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN IN 5 SECONDS. SAVING ALL MAPS..."5'
ExecStop=/bin/sleep 5
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"5'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"5'
[Install]
WantedBy=multi-user.target
Start Minecraft Server
sudo systemctl start minecraft@survival
Check minecraft server status
sudo systemctl status minecraft@survival
Enable minecraft server status
In order to start at system reboot:
sudo systemctl enable minecraft@survival