Minecraft raspberry pi server setup
Step 1
Setup the raspberry pi
For this project we're using the Raspberry Pi OS Lite, First go to https://www.raspberrypi.com/software/ and
downlod the imager tool.
When setting up the pi, select the correct model and than select the lite version with no desktop
environment. Than Make sure u set a password, wifi and enable SSH.
After the imager is finished boot the pi, now we need to find the IP adress of the pi. u can do this through
your routers control pannel or by plugging the pi into a monitor, it should say the IP at the top.
Alternatively u can type ifconfig on the pi's terminal.
Now lets connect to the server by opening the control panel and using ssh:
ssh [IP]
Replace IP with your own ip.
Step 2
Install JAVA on the pi
Beceause the pi has an arm processor and uses a special OS we cant install java normally, so we'll need to
use something else. And that is Liberica JDK.
The easiest way to install this is by adding Bellsofts APT repository using:
wget -q -O - https://download.bell-sw.com/pki/GPG-KEY-bellsoft | sudo apt-key add -
echo "deb https://apt.bell-sw.com/ stable main" | sudo tee /etc/apt/sources.list.d/bellsoft.list
and than install it using:
sudo apt update
sudo apt install bellsoft-java21
Replace java21 with the actual version u need, for the latest minecraft versions JDK21 should be fine.
Step 3
Setup the server
First we need to acquire the right files, we can get them from https://mcversions.net/.
Download the correct versions server.jar file.
To get the file to your pi were using scp:
scp [filepath] [ip]:[location]
For example:
scp c://users/user/downloads/server.jar 192.168.0.0:/home/user
Step 4
Start using the server
Now we start the server using :
java -Xmx1024M -Xms1024M -jar server.jar nogui
U will get an error saying u should accept the eula first.
We need to accept the eula by using:
nano eula.txt
Change the value from False to True
Than save file using CTRL + O Press Enter And exit using CTRL + X
If u restart the last command again:
java -Xmx1024M -Xms1024M -jar server.jar nogui
U should be able to join the server by entering this into minecraft:
[IP]:25565
Extra
If u wanna host the server online follow these steps.
Step 5
Forward your ip adress and port using the instructions for your own router. once forwarded u need to find the public ip adress of your raspberry pi using:
curl -4 ifconfig.me
Once u have that u can go to your domain registar and go to your dns setting. Create a new A record with the name being your subdomain or www if u want to use your main domain.
Type | Name | IP4 | ect... |
---|---|---|---|
A | subdomain | [PUBLIC_IP] |
If u are using cloudflare be sure to disable proxy and use dns only beceause otherwise it will not work.
After that u are going to need a SRV record like this:
Type | Name | Priority | Weight | Port | Target |
---|---|---|---|---|---|
SRV | _minecraft._tcp | 0 | 5 | 25565 (default) | subdomain.domain.tld |
Example
I'm using cloudflare so for me it is:
Type | Name | Priority | Weight | IPv4 | Proxy Status | TTL | Port | Target |
---|---|---|---|---|---|---|---|---|
A | server | - | - | 127.0.0.1 (your public adress here) | disabled | 2 min (default) | - | - |
SRV | _minecraft._tcp.mc | 0 (default) | 0 (default) | - | - | Auto (default) | 25565 (default) | server.domain.com |
Step 6 - Launch server when raspberry pi boots
If u want the server to launch automatically when the pi boots we will use a systemd service.
We'll start by installing screen so that the server can run in the background.
sudo apt update
sudo apt install -y screen default-jdk
After that we need to create a new service file for our minecraft server.
sudo tee /etc/systemd/system/minecraft.service >/dev/null <<'EOF'
[Unit]
Description=Minecraft Server (screen session)
After=network-online.target
Wants=network-online.target
[Service]
User=[Username]
Group=[Username]
WorkingDirectory=/home/[Username]
Type=oneshot
RemainAfterExit=yes
# ignore error if no session yet
ExecStartPre=-/usr/bin/screen -S mc -X quit
# start the server inside a detached screen named "mc"
# CHANGE server.jar below if your jar has a different name
ExecStart=/bin/bash -lc "/usr/bin/screen -DmS mc bash -lc 'cd /home/jonas && exec java -Xmx1024M
-Xms1024M -jar server.jar nogui'"
# stop cleanly by sending 'stop' + Enter
ExecStop=/usr/bin/screen -S mc -p 0 -X stuff "stop$(printf \\r)"
ExecStopPost=-/usr/bin/screen -S mc -X quit
StartLimitIntervalSec=0
[Install]
WantedBy=multi-user.target
EOF
Replace [Username] with your own username.
After that we need to enable the service so it starts on boot:
sudo systemctl daemon-reload
sudo systemctl enable minecraft
sudo systemctl start minecraft
systemctl status minecraft --no-pager
Important knowledge for using screen:
- To attach to the screen session, use: screen -r mc
- To detach from the screen session, press Ctrl + A followed by D
Conclusion
Congratulations! You have successfully set up a Minecraft server on your Raspberry Pi. You can now enjoy playing with your friends and customizing your server to your liking. Don't forget to regularly back up your world and keep your server updated.