How to Set Up and Optimize a Raspberry Pi Minecraft Server: A Comprehensive Guide
Aug 13, 2024

Setting up a Raspberry Pi Minecraft Server is a great way to host a small, cost-effective, and energy-efficient Minecraft world, especially for beginners and home users.
No Additional Hardware Required: A Raspberry Pi Minecraft Server does not require a powerful computer or expensive server hardware, making it ideal for lightweight hosting.
Low Power Consumption: Running a Minecraft server on Raspberry Pi consumes significantly less power than a traditional desktop or server, making it ideal for 24/7 operation.
Eco-Friendly: The reduced energy usage also translates to a smaller environmental footprint.
Full Control Over the Server: We have complete control over the server environment, allowing for custom configurations and settings.
Minecraft Pi Edition:There’s also a dedicated version of Minecraft for Raspberry Pi, which can be used for educational purposes or smaller-scale gaming.

Prerequisites
•Raspberry Pi 4 or later: Raspberry Pi 4 or later: Raspberry Pi 5 recommended for better performance — check out this Raspberry Pi OS guide on SunFounder Blog to understand the differences between OS versions.
•Raspberry Pi OS: 32-bit is sufficient, but 64-bit can provide better performance
•MicroSD card: 32GB recommende
•Network connection: Ethernet preferred, but Wi-Fi works too
Installation Step By Step Minecraft server on a Raspberry Pi
This section walks you through the complete Raspberry Pi Minecraft server setup, from system updates to launching the server for the first time
1. Update and Upgrade the System
Before learning how to host a Minecraft server on Raspberry Pi, it is important to update and upgrade the operating system to ensure stability and compatibility.
sudo apt update
sudo apt upgrade
2.To run a Raspberry Pi Minecraft server with Java, Minecraft currently requires Java 22 for optimal compatibility and performance.Install OpenJDK:
Install Java Minecraft requires Java 22 to run. Install OpenJDK:
sudo wget
https://download.java.net/java/GA/jdk22.0.2/c9ecb94cd31b495da20a27d4581645e8/9/GPL/openjdk-22.0.2_linux-aarch64_bin.tar.gz
sudo tar -xzf openjdk-22.0.2_linux-aarch64_bin.tar.gz
mv jdk-22.0.2 /opt
sudo update-alternatives --install /usr/bin/java java /opt/jdk-22.0.2/bin/java 1
sudo update-alternatives --config java
(IMPORTANT Select Option 1)

java -version

3.Create a Directory for the Server
mkdir minecraft
cd minecraft
4.Download the Minecraft Server: Visit the official Minecraft server download page to get the latest server .jar file needed for setup.
https://www.minecraft.net/en-us/download/server
5.Start the Minecraft Server Run the server for the first time to generate the required files:
In this Minecraft server Raspberry Pi tutorial, you will start the server for the first time to generate the required configuration files.
java -Xmx1024M -Xms1024M -jar server.jar nogui
This will likely fail with an error about the eula.txt file. You need to agree to the EULA.

6.Accept the EULA Open the eula.txt file and change eula=false to eula=true:
nano eula.txt
7.Start the Server Again
java -Xmx1024M -Xms1024M -jar server.jar nogui

Players can join the Minecraft server in a local LAN by entering the static IP address of the server host along with the port number, as explained in the official Minecraft LAN connection guide. For example, if the server host’s static IP is 192.168.0.2 and the port number is 25565, then you would connect to the server by addressing it as 192.168.0.2:25565.
Fowarding is a special network implementation that transmits or ‘forwards’ connections to a certain IP address and port number. This can be useful for a Minecraft server, as port forwarding lets players connect to your server over long distance and remotely through the internet, as described in the official Minecraft multiplayer networking guide.


When you are port forwarding on your router, it means you are transferring connections from your outside IP on the internet to your inside IP of your server host within the LAN.This allows players to connect remotely to your self-hosted Minecraft server on Raspberry Pi using your external IP address. (https://www.whatismyip.com/) which means you are ready to begin.
Optimizing Performance
This section focuses on Raspberry Pi Minecraft server performance optimization— for a comprehensive Raspberry Pi setup walkthrough, refer to this Raspberry Pi Ubuntu setup tutorial on SunFounder Blog.
● Increase Swap Size
The default swap size on a Raspberry Pi might not be enough. Increase it by editing the dphys-swapfile configuration:
sudo nano /etc/dphys-swapfile
Change CONF_SWAPSIZE=100 to CONF_SWAPSIZE=2048 (or a higher value if needed).
Apply the changes:
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start
● Overclock the Raspberry Pi (Optional):
Overclocking can improve performance, but it can also cause instability. Proceed with caution and make sure your Raspberry Pi has adequate cooling, as outlined in the official Raspberry Pi overclocking documentation.
● Optimize Java Arguments:
Adjust the Java arguments for better performance based on your Pi’s capabilities.
Running the Server Continuously
To keep the server running even after you log out, we can use screen or tmux.
Using screen:
1.Install screen:
sudo apt install screen
2.Start a new screen session and run the server:
screen -S minecraft
java -Xmx1024M -Xms1024M -jar server.jar nogui
We can detach from the screen session with Ctrl+A, D and reattach with screen -r minecraft.
Using tmux:
1.Install tmux:
sudo apt install tmux
2.Start a new tmux session and run the server:
tmux new -s minecraft
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
We can detach from the tmux session with Ctrl+B, D and reattach with tmux attach -t minecraft.
Security Considerations
Restrict Port Forwarding: If you need to make your server accessible over the internet, only forward the necessary port (usually TCP 25565). Avoid exposing other services running on your Raspberry Pi.
Create a Dedicated User: Run the Minecraft server under a dedicated non-root user with limited permissions to minimize the impact of any potential security breaches.
sudo adduser minecraft
sudo su – minecraft
Enable Online Mode: Ensure the server is set to online mode (online-mode=true in server.properties) to enforce Mojang's authentication and prevent unauthorized players from joining.
Official Documentation
● https://www.minecraft.net/en-us/download/server
● https://minecraft.wiki/w/Tutorials/Setting_up_a_server
In conclusion
Setting up a Raspberry Pi Minecraft server is an excellent way to explore both the Raspberry Pi’s capabilities and the expansive world of Minecraft. This project is not only cost-effective and energy-efficient but also provides full control over your own Minecraft server environment.Whether you're optimizing performance or ensuring security, this guide covers all the essential steps to build and manage a reliable Raspberry Pi Minecraft Server.Dive into the possibilities and enjoy the satisfaction of creating a robust and personalized Minecraft experience on your Raspberry Pi.
