Run a vanilla Minecraft server on Raspberry Pi

My partner has a teenage son, Michael, and like a lot of adults with a kid in their life I’ve come to know Minecraft. I even kind of like it. I was scared the first time night fell in survival mode, but I’ve made it from uber-noob to mere noob now and can usually make it through the night huddling in a basic wood block structure. I won’t get points for the aesthetics of my creations, but I survive and even have fun with it. Michael still makes fun of my noob’ness and will regularly switch to creative mode, grab a diamond sword, and off me just for fun. But whatever, I’m learning.

Michael and I have been playing with a Raspberry Pi lately. Actually, we bought two of the 1Gb Pi 2 Model B’s. These things are actually quite powerful little quad core computers so after a few simple projects we decided to use one of them as a dedicated Minecraft server.

The Raspberry Pi already comes with a cut down version of Minecraft that you can play directly on it, but that’s not what interested us. We wanted to create a “real” Minecraft server that we could leave running indefinitely and connect to from our local LAN anytime we wanted to.

There are quite a few tutorials out there on how to get this working, but most of them are of out of date. For example, we wasted a lot of time on our first try installing Java onto a Pi that already had it as part of the OS install. So, having gone through the process a few times, we figured we’d write this up for anyone else looking for a how to.

We should start with a note of caution. This is an installation guide for a vanilla server, and it frankly doesn’t perform very well on the Pi. On our first installation we got lucky and ended up with a seed for a really simple island world. The server runs flawlessly with that simple world. However, other worlds with more complexity have consistently crashed the server with two users. We’ll include the seed for “Michael and Jim’s island world” later in this post so you can use it if you’d like. Or, you may decide to modify this tutorial and install a Bukkit server. It should perform better but we haven’t tried it.

Here’s what you’ll need:

  • Raspberry Pi 2 Model B 1GB
  • Power supply
  • USB keyboard and mouse
  • An HDMI cable and an HDMI capable monitor or TV
  • Ethernet cable and an open port on your router
  • A fast micro SD card with at least 4GB (we used an 8GB class 10 card)

1) Create SD card

The first thing you need to do is get “new out of the box software,” (noobs) on your SD card. We used Disk Utility on a mac to format our card, downloaded noobs here, and then copied the contents of the noobs folder (not the folder, just the contents) to our SD card.

2) Set up your Raspberry Pi

At first you’ll be running your Raspberry Pi with a monitor and keyboard attached. Later you’ll go headless, but for now hook up keyboard, mouse, monitor, ethernet cable and install the micro SD card. Power it up.

3) Install the OS

Select the first checkbox for Raspbian and click install. This will take a little while as the OS is installed. It will re-boot when it’s done.

4) Configure your Raspberry Pi

When it re-boots it should boot into raspi-config. If it doesn’t you can type raspi-config to launch it. There are a few steps to go through here:

a) First, change the password for user “pi”. It defaults to “raspberry” but you might want to change it to something else.

b) Set “overclock” to pi2. This speeds things up a bit, but not so much that your silicon melts.

c) Go to advanced options and set your hostname to something cool.

d) Go to advanced options again and turn on SSH. You’ll be running it “headless” in a bit and you need SSH to access your pi remotely.

e) Go to advanced options again, select memory split, and set it to 16 (it won’t be running any graphics since it won’t have a monitor attached, this gives more memory back for other processes).

f) reboot it again so these changes take effect

5) Get your Pi’s IP address

When it reboots read it’s IP address from the screen. If you’re not sure where this is, type “ifconfig” and read the ethernet port IP address. You’ll need this address to ssh into it, and also later to direct connect your Minecraft game to the server.

6) ssh in to your Pi

Now, let’s make sure we can access your Pi remotely with ssh. Open up a terminal on your computer (on the mac we use command spacebar “term”, if you’re using a Windows machine you may need an SSH client) and type:

ssh <pi’s IP address> -l pi

Say yes when it asks you if you want to do this and type the password you created for your pi. If this works, you’re managing your Pi remotely and are ready to go headless.

7) Make it headless

Type:

sudo halt

This will shut down your pi. Remove it’s power supply and then unplug the keyboard, mouse, and HDMI cable. Leave the ethernet cable plugged in and then plug the power back in to boot it back up.

8) Verify Java installed and working

In old versions of NOOBS you had to manually install Java. But now it comes with it. Let’s make sure. ssh back in with:

ssh <ip address> -l pi

and once you are logged in verify that java is properly installed by typing:

java -version

You should see a version number etc.

9) Create Minecraft server directory

Now it’s time to create the directory where you are going to install Minecraft and then change directory into it. Type:

mkdir MCServer

then:

CD MCServer

to move into that directory.

10) Download Minecraft

At the time of this writing, Minecraft 1.8.4 is the most recent version. You can check to see if there is a later version (and get it’s address) by going here. For a later version, just modify the “1.8.4” to the new version number. Let’s download the most recent one by typing:

wget https://s3.amazonaws.com/Minecraft.Download/versions/1.8.4/minecraft_server.1.8.4.jar

You should see an arrow go across as it downloads the file. When it finishes if you type “ls” you should see minecraft_server.1.8.4.jar listed in the contents of MCServer.

11) Run your Minecraft Server (it will fail)

The first time we try to run the downloaded server it’s going to fail. We have to accept the user agreement. But we have to try to run it once so that the file eula.txt will get created. To run it type:

java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.4.jar nogui

It will take a while and then fail.

12) Accept the EULA

So, let’s accept the user agreement by opening eula.txt with a text editor. Type:

nano eula.txt

Then using the editor change “false” to “true”, use ctrl-X  and type “y” to save your changes. If you want to verify that you successfully made the changes to the file type:

cat eula.txt

This will show you the contents of the file.

13) Run your server again

Let’s run the server again now to build our world. Type

java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.4.jar nogui

(note, you don’t have to type the whole thing again. Use your up/down keys to find this command from the previous time you typed it).

This time it will take a while because it’s going to build the world. As soon as it builds we’re going to shut it down again so that we can make a change or two to the server properties file.

14) Stop your server to modify properties

After it finishes building, type:

stop

to stop your Minecraft server.

15) Modify the server.properties file

If you do an “ls” now you’ll see that the file MCServer has a lot more stuff in it. We want to modify the file called server.properties so that our server will perform better. So, type:

nano server.properties

If you scroll down you’ll see that view distance is set to 10. Change it to 6. You can also change your server name by changing the MOTD field.

Save this new server.properties file.

16) Play Minecraft! (and see if your server is keeping up)

Let’s give it a try. Start your Minecraft client on your computer, go to multiplayer, click on “direct connect” and enter the IP address of your Pi. You should be in the game.

While you’re at it, see if you’re Pi is keeping up with the load ok. You can open another terminal window, ssh into your pi, and type

top

to see your pi’s performance characteristics. The two interesting bits to look at are CPU% and load average. This is a one cpu machine so a load factor of 1 means you’re using the whole thing. Also, in the Minecraft server window you already had open you can watch for indications that the server is getting overloaded. It will complain that it can’t keep up if it is beginning to fail.

17) Set up “screen” so your server will run if you close SSH

At this point, if your server is performing ok, you can just play Minecraft with it. If you friends or family on your local LAN they can log into it too. You probably won’t be able to support more than a few users at a time on it, but give it a try. If it’s not performing (if it’s lagging or the server is crashing) I’ll show in a few steps how you can seed your world with one that I know performs well.

The problem right now is that if you close your ssh session the server will crash. It’s not very convenient to have to leave your computer on to make your server keep running, so let’s fix that by installing a program called “screen” that will let you create a virtual screen for your server to live in even when your ssh session is closed. To install screen type:

sudo apt-get install screen

sudo makes the command run as “root” user and apt-get is the Raspberry Pi software package manager. With screen installed you can type:

screen -ls

to see which screens are running. Let’s shut down your Minecraft server and then restart it in a screen. Go to your Minecraft server terminal and type

stop

Then type

screen -S <screen name>

(I usually call my minecraft screen “mcs” just to keep it short and simple).

18) Create a startup script

While we are it let’s go ahead and make a start script for Minecraft so we don’t have to type so much when we start it. Type

nano start.sh

Then paste “java -Xmx1024M -Xms1024M -jar minecraft_server.1.8.4.jar nogui” into it. Save the file.

Btw, those Xmx and Xms statements set memory sizes for Java. We haven’t played around with other values to see if they improve performance but you might want to.

Now, to start your server just type:

sh ./start.sh

19) Detach your screen so you can close ssh

Your Minecraft server is running inside the screen called “mcs” now. If you want to you can “detach” from the screen and close your ssh session and the server will keep running. Detach by pressing ctrl-a and then type “d”

Try playing Minecraft again to prove that the server is still running.

If you want to reattach to your screen type:

screen -ls

Note the session number in front of your screen name. It might look something like 2858.mcs

Then to reattach type:

screen -r 2858.mcs

(or whatever yours says). Now you can control your server from the command line again.

20) Make a simpler (better performing) world

Ok, if your server isn’t running well, you can force it to create a new (simple) world by going back into server.properties and changing two settings. Type:

nano server.properties

Then change level-name=world to level-name=simpleworld (or whatever you want to name it)

Then change level-seed= to level-seed=-8248690372160644962

We’ve been running a server for two weeks with that seed and it has run very well. It’s an island world and we just got lucky that it was easy on the server. When you restart your server with these properties set it will create a new world in the simpleworld folder that uses that seed. It should perform well.

That’s it. You should have a well-performing world running on a headless Raspberry Pi that you can hide away somewhere (near your router so you can use an ethernet cable. You probably don’t want to use wi-fi as that saps some performance on the Pi).

If you want to share your server with your friends that aren’t on your local LAN you’ll have to share it on the Internet. To do that you’ll have to set up port forwarding on your router and get dynamic DNS working (since you probably don’t have a fixed IP). On “normal” servers people often use Hamachi or another VPN to make this unnecessary, but I don’t think you can run Hamachi on a PI so you’re going to have to do this the hard way. We haven’t set this up so we can’t provide you the steps. If you do it and document it please share.

We’ve gone through this setup process three times so it should all work. But if you find any problems please let us know in the comments.

Have fun!

Leave a Reply

Your email address will not be published / Required fields are marked *