How to Make a Minecraft Server on Raspberry Pi
If you want to create a private Minecraft world to share with your friends online, you need a place to host that experience. You can pay a whopping $7.99 per month for Minecraft Realms (opens in new tab)which is easy to use but doesn’t have all the customization options, or you can rent a Minecraft server from a paid hosting service like Shockbyte (opens in new tab). Or set up your own Minecraft server on a Raspberry Pi and have it hosted for free right from your living room.
Note that you will need either a Raspberry Pi 3 or 4, preferably a 4 with at least 2GB of RAM. And all traffic on the server will come and go through your internet service at home. So if you plan to have a lot of users all the time, it may take some bandwidth. But if you’re just planning to play with some friends, building a Raspberry Pi Minecraft server is easy, cheap, and fun.
Below we will show you how to set up a Minecraft server on your Raspberry Pi, making sure the server starts at boot and allowing connections from outside your local network. We also explain how to log into this server from Minecraft Java Edition. Note that we’re using a basic vanilla Minecraft server and a Java edition with no mods. However, once you get familiar with this guide, you can install server-side mods or different versions of the server.
How to set up a Raspberry Pi Minecraft server
1. Set up a Raspberry Pi if you don’t have one yet Check out our stories on how to set up a Raspberry Pi or how to set up a headless Raspberry Pi (if you want to control it remotely).
2. Open a terminal window on the Pi or an SSH connection to the Raspberry Pi.
3. Make sure your Raspberry Pi is up to dateby running the latest update commands.
sudo apt update
sudo apt upgrade -y
4. Install JDK and git. The Java Development Kit (JDK) is the basis for the Minecraft Java Edition. Minecraft wouldn’t work without the JDK.
sudo apt install default-jdk
5. Create a directory to save the files and Enter this directory. We call ours mcserver.
mkdir mcserver
cd mcserver
6. On your PC navigate to Minecraft.net server download page and copy the address the latest server JAR file.
7. Type wget
wget https://piston-data.mojang.com/v1/objects/f69c284232d7c7580bd89a5a4931c3581eae1378/server.jar
8th. Start the server with the following command. This will allocate 1GB of RAM to the server and then run the downloaded .jar file.
java -Xmx1024M -Xms1024M -jar server.jar
Add to nogui to the end if you want to start without an interface. You will receive an error message stating that you must agree to the EULA.
9. Open eula.txt for editing. It is easiest to use Nano.
nano eula.txt
10 Change eula=false to eula=true to the file and hit CTRL + X, then press Y and Enter save and exit.
11. Restart the server.
java -Xmx1024M -Xms1024M -jar server.jar
It takes a few minutes to start as a world is generated and a spawn area is prepared. You’ll see a percentage as it goes.
Your server should now be running and you can log in. However, if you were running the server from an SSH window, it will close the moment you close the window (unless you put “nohup” before the server load command). And even if you’re running it from a terminal window on the Pi (or via VNC), the server isn’t set to restart in case you need to restart the Raspberry Pi.
Below we will show you how to create a script that starts the Minecraft server every time you boot the Raspberry Pi and should also restart the Minecraft server if it crashes but the Pi itself does not.
How to start the Raspberry Pi Minecraft Server at boot
1. Create a new file called mcstart.sh in the same folder as the server files (mcserver in our case). You can create and open the file with nano.
nano mcstart.sh
2. Enter the following code to your bash script.
#!/bin/bash
cd ~/mcserver
while true
do
java -Xmx1024M -Xms1024M -jar server.jar
sleep 10
done
What we’re doing here is changing to the directory where the server is located and then running an infinite loop that starts the server and then if it ever stops, waits 10 seconds and starts it again. If the server never crashes, it will never reach the “sleep 10” part of the loop.
If the path to your Minecraft server on your Raspberry Pi is something other than /mcserver, make sure to change that part of the script.
3. Save and close the file by pressing CTRL + X.
4. Set the mcstart.sh file to be executable from all users.
chmod a+x mcstart.sh
So now you can just run the mcstart command from the command line, but that won’t do you much good unless the system runs it automatically at boot.
5. Open the crontab editor.
crontab -e
When you first open crontab on this Raspberry Pi, you will be prompted to choose an editor. Select Nano when given the choice.
6. Type @reboot and the path to mcstart.sh at the end of the crontab file and save it by pressing CTRL + X. In our case, the line looked like this, but yours may vary depending on the path to your home directory and the name of your server directory.
@reboot /home/pi/mcserver/mcstart.sh
7. Reboot your Raspberry Pi and see if it works.
How to put the Raspberry Minecraft server on the Internet
If you have a Minecraft server installed on your Raspberry Pi and configured to run on every boot, you and anyone on your local network can now log in. However, if not everyone you want to play with is at your house, you should make this server available on the internet.
1. Configure the Raspberry Pi to use a static IP address. If you don’t know how to do this, check out our tutorial on how to get Raspberry Pi to use a static IP address. A static IP is beneficial to you as you want to ensure that the local IP v4 number is the same even on reboot.
2. Set a port forwarding rule on your router forwarding port 25565 to the internal IP address of your Raspberry Pi Minecraft server. The process will be slightly different on each router. You need to go into the admin panel, look for the port forwarding menu and then create a rule.
3. Find your public IP v4 address. The easiest way is to navigate to whatismyipaddress.com (opens in new tab). Googling “what’s my IP address” usually works, but sometimes this way only gives you the IP v6 address.
You can now give this address to your friends and they can use it to log into your server. However, unless you pay your ISP extra for a fixed IP address, you cannot rely on that IP address staying the same. If you unplug your modem, temporarily lose power, or experience something that takes your home offline, you may have a different IP when you turn it back on and need to look it up again.
If you’re happy with giving your friends the IP address every time they want to log in, you can stop here. Otherwise, consider the next step.
4. Use No IPa dynamic DNS service, to create a hostname which forwards traffic directly to your current IP address at home. The service has a free tier that you can sign up for at noip.com (opens in new tab) The company also has instructions for installing the appropriate software on your Pi (opens in new tab) .
Logging into a Raspberry Pi Minecraft server
1. Start the Java edition of Minecraft on the computer you want to play from.
2. Choose Multiplayer.
3. Click Add Server.
5. Enter the hostname or IP address of the server and give it a name (or leave it as “A Minecraft Server”. This name is for your convenience only. Click Done when done.
The server will appear in your server list.
6. Click on the icon so the server can enter it.
And that should get you playing Minecraft on your local Raspberry Pi.