Minecraft has been with us since 2009. Despite all these years on the market, Minecraft's popularity is still enormous. The reasons for this success are not hard to find; Minecraft offers complete freedom. The community creates amazing projects in the game, such as functional computers, mechanisms that play songs, or replicas of popular places. One aspect that made many of these projects possible is the multiplayer mode, which we'll configure today.
Requirements
To install a Minecraft server on Raspberry Pi 5, theoretically, you only need... a Raspberry Pi 5. Of course, the Raspberry Pi must be pre-configured, and this process is detailed in this post. Another important aspect is our internet connection. If we want to play on our server on a local network, for example, only within our home, the internet issue is simply that the software must be downloadable. However, if we plan to play with friends over the internet, we need to check if our internet service provider provides us with a public IP address along with enabled external communication. The easiest way to check this is by contacting the technical support of the internet service provider.
What is Spigot?
Spigot is an unofficial Minecraft server that is directly based on Mojang's official server. Spigot's advantage over the official server is the ability to install external plugins, which are various add-ons that we can use according to our needs. There are plugins that, for example, introduce economy, provide a game map in the browser, control advanced permissions, or add new game mechanisms, etc.
Installation
Preparation
The installation of the Minecraft server will take place in the terminal. After starting the terminal or connecting via SSH to our Raspberry Pi, we need to install basic packages required for server installation. Just copy or type each command and press enter to execute. (In some terminals, text pasting is done with the right mouse button)
sudo apt-get update && sudo apt-get install wget apt-transport-https git -y
Java Installation
Minecraft Java Edition, as the name suggests, is written in the Java programming language. To run the game correctly, as well as its server, Java must be installed on our Raspberry Pi.
To do this, we need to install the keys in the system that will allow us to add the repository containing Java correctly.
sudo mkdir -p /etc/apt/keyrings
sudo wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | sudo tee /etc/apt/keyrings/adoptium.asc
Now we can add the repository of interest to our system's sources list.
sudo echo "deb [signed-by=/etc/apt/keyrings/adoptium.asc] https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | sudo tee /etc/apt/sources.list.d/adoptium.list
The last step of the Java installation is to update the list of packages ready to be installed on our system along with the actual Java installation.
sudo apt-get update
sudo apt-get install temurin-21-jdk -y
Once everything is done, we can make sure that Java has been installed correctly. By executing the following command, the current version of Java should be displayed on the screen.
java -version
Spigot Installation
Once Java is installed, we can proceed to install the server itself. We start by creating a directory to install the Spigot server files.
sudo mkdir /opt/minecraft/buildtools -p
cd /opt/minecraft/buildtools
The Spigot executable file needs to be compiled, without going into details, this is preparing the ready-to-run file. For this purpose, the BuildTools tool is prepared. We download it with the command:
sudo wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
Once the tool is downloaded, we can proceed to compile the server and copy it to the destination. Unfortunately, this may take a while.
sudo java -jar BuildTools.jar --rev 1.20.5
sudo cp spigot-1.20.5.jar ../spigot-1.20.5.jar
cd ..
Once the file is ready, we can proceed to the first run of the server. We will need a startup script. We'll create it with the following command. At this point, we can adjust the amount of RAM we allocate to Spigot. In the example, 3GB of RAM is allocated.
sudo echo "java -Xmx3G -Xms3G -jar spigot-1.20.5.jar nogui" | sudo tee run.sh
sudo echo "eula=true" | sudo tee eula.txt
Done, the Minecraft server is installed. All that's left is to start it up and test it. To do this, you need to check the IP address of the Raspberry Pi, which you will need to connect to the server. Once you know the IP address, you can proceed with the first run.
hostname -I
sudo bash run.sh
The first server startup will take a little longer due to the need to generate a new world. After a while, you will be able to connect to our server.
Success, the server is up and visible in the Minecraft client. We can connect and play.
To shut down the server, you need to use the "stop" command in the server console.
stop
Adding a System Service
In its current form, the server must be started and stopped manually. To automate this process, we can create a system service in Linux. This will allow us to run the server "in the background", automatically start it when the system starts up (particularly useful in case of power failure), and easily control shutting down, starting up, and resetting our Minecraft server.
The first step is to add a system user and grant permissions to the Spigot server. This user will be responsible for running the server.
sudo useradd -r -s /bin/false spigot
sudo chown -R spigot:spigot /opt/minecraft
sudo chmod -R 750 /opt/minecraft
Once the user is created, check if the permissions are correctly set. You can do this with the following command, which will start our server as the "spigot" user. The server should start, and we will be able to connect to it. After verifying that it works, shut down the Spigot server.
sudo -u spigot bash run.sh
stop
Now we can create the configuration file for our service. The following (unfortunately long) command will create a fully ready configuration.
sudo echo -e "[Unit]\nDescription=SpigotServer\nAfter=multi-user.target\n\n[Service]\nType=simple\nUser=spigot\nRestart=always\nRestartSec=1\nWorkingDirectory=/opt/minecraft\nExecStart=bash /opt/minecraft/run.sh\n\n[Install]\nWantedBy=multi-user.target\n " | sudo tee /etc/systemd/system/spigot.service
If everything is fine, you should see the contents of the file like this:
Now we can check if our service is working. After starting the service, our server should be ready to play in a few seconds.
sudo systemctl start spigot
The last step is to mark the service as active, which will enable automatic start of the service when the Raspberry Pi is started.
sudo systemctl enable spigot
From now on, you can control your Spigot server with these simple commands:
Checking the service status
sudo service spigot status
Starting the service
sudo service spigot start
Stopping the service
sudo service spigot stop
Restarting the service
sudo service spigot restart
Summary
I hope the installation went smoothly and the instructions were clear. Have fun playing :) Also, feel free to check out other posts on the blog to discover what else Raspberry Pi can do, and more!