Skip to main content

Minecraft Server

Notes from my recent first foray into Java edition of Minecraft and a dedicated server with some mods. 

Don't use the mojang / microsoft provided server.jar. Requires Fabric to run mods (or forge, but I used fabric)

If you know what you're doing in Linux it's easy to use different users, home directory structures, whatever. This is just what I did.

Note this hasn't covered firewalls. If you're opening it up to the public you'll want to lock it down and probably whitelist users that are permitted to connect too. 

Basic instructions 

Start from clean Ubuntu install. Add repository for Java runtimes, then install java 21, git and build tools

sudo apt update
sudo apt upgrade
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt install openjdk-21-jdk-headless
sudo apt install git build-essential

 Created a user 'mc-fabric' with no password to run Minecraft server. Home directory /opt/mc-fabric

sudo useradd -r -m -U -d /opt/mc-fabric -s /bin/bash mc-fabric

change user to mc-fabric

sudo su - mc-fabric

should dump into mc-fabric's home directory (/opt/mc-fabric as above). Make directories 'tools', 'backups' and 'server'

mkdir tools
mkdir server
mkdir backup

change into server directory and download the server installer file

curl -OJ https://meta.fabricmc.net/v2/versions/loader/1.20.6/0.15.11/1.0.1/server/jar

Launch the server installer. This will download the minecraft server and do some initial setup before dropping back to command prompt.

java -Xmx2G -jar fabric-server-mc.1.20.6-loader.0.15.11-launcher.1.0.1.jar nogui

Edit eula.txt with your preferred text editor and change 'eula=false' to 'eula=true'

Edit server.preferences. find and alter the following lines (Feel free to set other stuff like server name, world name etc too)

enable-rcon=true
rcon.password=<insert a password you create here>

You could just run 

java -Xmx2G -jar fabric-server-mc.1.20.6-loader.0.15.11-launcher.1.0.1.jar nogui

from here and it should work, but we'll do a little more yet.

change into the tools directory

cd /opt/mc-fabric/tools

Download and build mcrcon (MineCraft Remote Console)

git clone https://github.com/Tiiffi/mcrcon.git
cd mcrcon/
gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c

now run ./mcrcon -h and it should display help text if everything's worked correctly.

Lastly we'll create a systemd service. This needs to be done as sudo, so type

exit

to drop back to your standard user rather than mc-fabric. Then edit  /etc/systemd/system/minecraft.service AS SUDO with your editor of choice. Copy this into it

[Unit]
Description=Minecraft Java-Fabric Server
After=network.target
[Service]
User=mc-fabric
Nice=1
KillMode=none
SuccessExitStatus=0 1
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
WorkingDirectory=/opt/mc-fabric/server
ExecStart=/usr/bin/java -Xmx6144M -Xms2048M -jar /opt/mc-fabric/server/fabric-server-mc.1.20.6-loader.0.15.11-launcher.1.0.1.jar nogui
ExecStop=/opt/mc-fabric/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p <rcon.password you created in server.properties> stop
[Install]
WantedBy=multi-user.target

Now you should be able to start your server with 

sudo systemctl start minecraft.service

Stop it with

sudo systemctl stop minecraft.service

make it autostart on boot with

sudo systemctl enable minecraft.service

MODS

Stop your server.

Change to the mc-fabric user, then change directory into the server/mods directory. 

First mod you'll need is fabric.api. It can be downloaded with

wget https://cdn.modrinth.com/data/P7dR8mSH/versions/MtIGbixh/fabric-api-0.99.4%2B1.20.6.jar

From there, any other mods you want to install - find the link to the  .jar file (There's typically versions for Forge and Fabric, make sure you're using Fabric) and then use wget with the link as above. This will download the file and save it in the directory you run the command from (make sure you're in the mods directory)

Start the server again and it should run the mods.

References

https://fabricmc.net/use/server/