How to Set Up and Optimize a Raspberry Pi Minecraft Server: A Comprehensive Guide

How to Set Up and Optimize a Raspberry Pi Minecraft Server: A Comprehensive Guide

Aug 13, 2024

Raspberry Pi Minecraft Server

Using a Raspberry Pi to host a Minecraft server offers several benefits, particularly for those looking to create a small, cost-effective, and energy-efficient server.

No Additional Hardware Required: We don’t need a powerful computer or expensive server hardware to run a Minecraft server.

Low Power Consumption:
Raspberry Pi consumes significantly less power than a traditional desktop or server, making it more energy-efficient and cheaper to run 24/7.

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.

图片2.png__PID:8e9175de-3b3d-4541-a8ef-cba5fb05a229

Prerequisites

● Raspberry Pi 4 or later: Raspberry Pi 5 recommended for better performance
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

1. Update and Upgrade the System
sudo apt update
sudo apt upgrade


2.
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)

图片3.png__PID:75de3b3d-d541-48ef-8ba5-fb05a229d22f

java -version

图片4.png__PID:cba5fb05-a229-422f-a36d-e688fb7d15f0

3.Create a Directory for the Server
mkdir minecraft
cd minecraft


4.Download the Minecraft Server: Visit the Minecraft server download page and get the link to the server jar file.
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:
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.

图片5.png__PID:fb7d15f0-ae39-4323-ad1c-cffc3564bee4

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

图片7.png__PID:ed1ccffc-3564-4ee4-b770-b09b9519e1c3

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. 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 forwading lets players connect to your server over long distance and remotely through the internet.

图片8.png__PID:3564bee4-3770-409b-9519-e1c3da8911aa图片9.png__PID:11aa2c17-cfb7-4454-9b14-ea93d8f6a3fe

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. Because of that, players can connect into your Minecraft server via your external IP address (https://www.whatismyip.com/) which means you are ready to begin.

Optimizing Performance

     ● 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.

     ● 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 the security of your server, this guide has covered all the essential steps. Dive into the possibilities and enjoy the satisfaction of creating a robust and personalized Minecraft experience on your Raspberry Pi.

Building a Secure and Customizable Raspberry Pi Security Camera: A Comprehensive Guide Back to News Mastering Raspberry Pi Desktop: A Comprehensive Guide to Remote Desktop Solutions