How to Create a Minecraft Server on Raspberry Pi

0

If you want to create a private Minecraft world that you can share with your friends online, you need a place to host that experience. You can pay $7.99 per month for Minecraft Realms (opens in a 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 such as Shockbyte (opens in a new tab). Or you can set up your own Minecraft server on a Raspberry Pi and have it hosted for free from your living room.

Note that you will need a Raspberry Pi 3 or 4, preferably a 4 with at least 2 GB of RAM. And all traffic on the server will come in and out through your home internet service, so if you plan on having a ton of users all the time, it might take some bandwidth. But if you just plan to play with a few friends, creating a Raspberry Pi Minecraft server is easy, cheap, and fun.

Below we’ll show you how to set up a Minecraft server on your Raspberry Pi, make sure the server starts on boot and allows connections from outside your local network. We will also explain how to connect to this server from Minecraft Java Edition. Note that we are using a plain vanilla Minecraft server and Java edition, with no mods. However, once you understand these instructions, you can install server-side mods or different server versions.

How to Set Up a Raspberry Pi Minecraft Server

1. Configure a Raspberry Pi if you don’t already have one. Check out our stories on setting up a Raspberry Pi or setting 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 of Minecraft Java Edition. Without the JDK, Minecraft wouldn’t work.

sudo apt install default-jdk

5. Create a directory to store files and enter this directory. We will call ours mcserver.

mkdir mcserver
cd mcserver

6. On your PC, navigate to the Minecraft.net server download page and copy address from the latest server jar file.

Copy link address from server

(Image credit: Tom’s Hardware)

seven. Enter wget at the command prompt where is the url of the jar file you copied. For example, ours was:

wget https://piston-data.mojang.com/v1/objects/f69c284232d7c7580bd89a5a4931c3581eae1378/server.jar

8. Start the server using the following command. This will allocate 1 GB of RAM to the server and then run the downloaded .jar file.

java -Xmx1024M -Xms1024M -jar server.jar

To add nogi all the way if you want to launch without an interface. You will receive an error message indicating that you must accept the EULA.

error message asking for EULA

(Image credit: Tom’s Hardware)

9. Open eula.txt to edit it. It’s easier to use nano.

nano eula.txt

ten. Replace eula=false with eula=true in the file and press CTRL + X then press Y and Enter to save and exit.

set eula=true

(Image credit: Tom’s Hardware)

11. Restart the server.

java -Xmx1024M -Xms1024M -jar server.jar

It will take several minutes to start as it generates a world and prepares a spawn area. You will see a percentage as you go.

minecraft server launch

(Image credit: Tom’s Hardware)

Your server should now be running and you can connect to it. However, if you ran the server from an SSH window, it will exit the moment you close the window (unless you put “nohup” before the server load command). And, even if you run it from a terminal window on the Pi (or via VNC), the server is not configured to restart if you need to restart the Raspberry Pi.

Below we’ll show you how to create a script that will start the Minecraft server every time you start the Raspberry Pi and should also restart the Minecraft server if it crashes, but not the Pi itself.

How to Start Raspberry Pi Minecraft Server on Boot

1. Create a new file called mcstart.sh in the same folder as the server files (in our case, mcserver). 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, then running an endless loop that starts the server, then, if it stops, waits 10 seconds and restarts it. If the server never crashes, it will never reach the “sleep 10” part of the loop.

If the path to your Minecraft server is other than /mcserver on your Raspberry Pi, be sure to edit that part of the script.

3. Save and Exit the file by pressing CTRL+X.

4. Set the mcstart.sh file to be executable by all users.

chmod a+x mcstart.sh

So now you can just use the mcstart command from the command line, but it won’t do you any good unless the system automatically runs it on startup.

5. Open the crontab editor.

crontab -e

If this is your first time opening crontab on this Raspberry Pi, you will be asked to select an editor. Select nano if you have a choice.

6. Enter @reboot and the path to mcstart.sh at the bottom 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 you gave to your server directory.

@reboot /home/pi/mcserver/mcstart.sh

seven. Restart your raspberry pi and see if it works.

How to Put the Raspberry Minecraft Server on the Internet

If you installed a Minecraft server on your Raspberry Pi and configured it to run on every boot, you and anyone on your local network can now connect to it. However, unless everyone you want to play with is at your house, you’ll want to make this server available on the internet.

1. Configure the Raspberry Pi to use a static IP address address. If you’re not sure how to do this, check out our tutorial on how to get Raspberry Pi to use a static IP address. A static IP address benefits you, because you want to make sure its local IP v4 number is the same even if you restart it.

Configure your Pi to use a static IP

(Image credit: future)

2. Define a port forwarding rule on your router which redirects 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 to the admin panel, find the port forwarding menu, and then create a rule.

Forward port 25565 to your Minecraft server

(Image credit: future)

3. Determine your v4 public IP address. The easiest way is to navigate to whatismyipaddress.com (opens in a new tab). Googling “what is my IP address” usually works, but sometimes you just get the v6 IP address that way.

Screenshot of whatismyipaddress.com

(Image credit: future)

You can now give this address to your friends and they can use it to connect to your server. However, unless you pay extra to your ISP for a fixed IP address, you cannot expect that IP address to stay the same. If you unplug your modem, temporarily lose power, or encounter something that takes your home offline, you may have a different IP address when you return and need to search for it again.

If you are happy giving your friends the IP address every time they want to connect, you can stop here. If not, go to the next step.

4. Use without IPa dynamic DNS service, to create a hostname which directs traffic directly to your current personal IP address. The service has a free tier which you can sign up for at noip.com (opens in a new tab) The company also has instructions for installing the appropriate software on your Pi. (opens in a new tab) .

Connecting to a Raspberry Pi Minecraft Server

1. Launch Minecraft Java Edition on the computer from which you want to play.

2. Select Multiplayer.

select multiplayer

(Image credit: Tom’s Hardware)

3. Click Add Server.

click add server

(Image credit: Tom’s Hardware)

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 just for your benefit. Click Done once you have finished.

enter server address

(Image credit: Tom’s Hardware)

The server will appear on your server list.

6. Click the icon for the server to enter.

click the icon to enter

(Image credit: Tom’s Hardware)

And that should allow you to play on your local Raspberry Pi Minecraft server.

Share.

About Author

Comments are closed.