Install Minecraft and Minecraft PE server op the Raspberry PI

I combined information from 2 different webpages in this article:

The original articles can you read here:

First the installation of a Minecraft server

I asume that you have a Raspberry PI 2 or 3 working and SSH login working as well. I asume that your login name is "pi" and that you didn't change that somewhere.

Firts we install some aditional packages from the terminal:

sudo apt install netatalk screen avahi-daemon

Try typing screen -list. If it complains that there is no screen command, go back to the previous step and install it. Otherwise, you should get a message of the type No Sockets found: that’s good!

Now enter

sudo raspi-config

    1. First, tell it to expand the file system so that it uses all the SD card.

    2. For safety, I recommend changing the default password (the default account is called pi with password raspberry).

    3. You want to tell the Raspberry Pi to boot in the shell: Console Autologin Text console, automatically logged in as 'pi' user.

    4. In Internationalisation Options, you may want to configure the time and locale.

    5. You may want to set the overclocking to the maximum setting, if the option is available. (Overclocking is optional and may cause instabilities and crashes.)

    6. You want to assign the minimum amount of memory to the GPU (16 is enough) from Advanced Options.

    7. Under the advanced options, you may want to check the Hostname value. It defaults to raspberrypi, I assume you are not changing it. You may need to change it if you have several Raspberry Pis on your network.

    8. Make sure that the ssh server is on. The term “ssh” stands for “secure shell”, it is a way to connect to the shell of another machine remotely and securely (with encryption).

    9. A nice trick at this point is to find the IP address of the Raspberry Pi on your network. Type ifconfig|grep "inet ". The result might contain two lines, one line with the string “addr:127.0.0.1” and another with a string that looks like “addr:192.168.1.87”. In that case, 192.168.1.87 is your IP address (your address will be different). Note that if you can access your router, you should also be able to find the IP address of your Raspberry Pi, but not everybody can or should access their router.

You can exit raspi-config which should bring you back to the bash shell. Reboot the Raspberry Pi by typing sudo reboot in the bash shell.

Now enter

mkdir minecraft && cd minecraft

wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar

java -jar BuildTools.jar

This will create a file spigot-1.12.2.jar (or a newer numner). On my Raspberry PI it took more that 20 minutes. That's good.

Once this is done, start the server for the first time:

java -jar -Xms512M -Xmx1008M spigot-1.12.2.jar nogui

This will create a file called eula.txt. You need to edit it with the command nano eula.txt. Make sure it reads eula=true.

nano eula.txt

Start the server a second time:

java -jar -Xms512M -Xmx1008M spigot-1.12.2.jar nogui

This will take a long time again.

Once the server return the command prompt, it should be operational. Have a Minecraft player connect to raspberrypi.local.

Once you have verified that everything works, type

stop

We are going to create a convenient script to start the server. Type

nano minecraft.sh

and write the following four lines of code:

if ! screen -list | grep -q "minecraft"; then cd /home/pi/minecraft screen -S minecraft -d -m java -jar -Xms512M -Xmx1008M spigot-1.12.2.jar nogui fi

It is really important to type the 4-line script (or copy and paste it) accurately. You can also grab the minecraft.sh file from GitHub if you prefer.

The if clause helps to make sure that only one instance runs at any one time (it is not perfect, but should be good enough).

Some people have trouble copying and pasting the content of the minecraft.sh file. As a sanity test, type

wc -l minecraft.sh

The shell should return 4 minecraft.sh indicating that the script has 4 lines, if you do not see the number 4, do not continue! If you get any number other than 4, then you did not correctly copied the script, it will not work. I am aware that your browser might represent on the web page the 4 lines as more than 4 lines, but there are exactly 4 lines to be copied.

We also want to check the syntax of the script, so type

bash -n minecraft.sh

this command should return immediately without any error. Now that we have verified that the script has four lines and has a valid syntax, let us make the script executable: chmod +x minecraft.sh.

You did remember that I am assuming that you have a file called

spigot-1.12.2.jar

right? If your file name differs, please adapt the script accordingly. Please read the script again, make sure that everything is ok.

To make the server more stable, type

nano spigot.yml

Set view-distance: 8.

This may or may not be necessary, you can experiment. The downside of this setting is that the clients will get a more limited view.

Optionally, you may want to type

nano server.properties

and modify the greeting message given by the motd variable.

We want the server to start automatically when the Raspberry Pi reboots, so type

sudo nano /etc/rc.local

and enter

su -l pi -c /home/pi/minecraft/minecraft.sh

right before the exit command.

Start the server again using the script:

./minecraft.sh

while in the bash shell. (I recommend against typing sudo ./minecraft.sh as it would run the server as the root user: you do not want that.) The script will return you to the shell. There should be no error, if there is an error then you need to backtrack and start again: you missed a step somewhere. (These instructions have been thoroughly tested: chances are good that you did not follow them correctly if you are getting an error.)

Your minecraft server (Spigot) is managed using its own console. The console operates a bit like the bash shell: you type commands followed by the enter key. It is also used by the server to log its operations, so you can see what it is currently doing. To access the console of the minecraft server type screen -r minecraft, to return to the shell type ctrl-a d. At any point, you can now disconnect from the server. The server is still running. You do not need to remain connected to the Raspberry Pi.

Spigot makes use of temporary files (located in /tmp). This can cause performance issues and instabilities on a Raspberry Pi. It may even shorten the life of your SD card. It might be better to have temporary files reside in memory. To alleviate the problem, open the file /etc/fstab with a text editor such as nano as root (e.g., type

sudo nano /etc/fstab

It should look something like this:

proc /proc proc defaults 0 0/dev/mmcblk0p6 /boot vfat defaults 0 2/dev/mmcblk0p7 / ext4 defaults,noatime 0 1

The important point is that there should be no line where the second entry is “/tmp”. Then append a new line:

tmpfs /tmp tmpfs nodev,nosuid,size=1M 0 0

Where you append/insert this line does not matter, but please note that you need to create a new line. The format of the fstab file requires that there is one entry per line. For this change to take effect, I recommend simply stopping the Minecraft server, by going to the server prompt (type screen -r minecraft if needed) and then typing stop. Then you can safely reboot the Raspberry Pi (e.g., with the sudo reboot command). If you have done everything right, the server should automatically start following a reboot sequence. In the future, the temporary files will get written to /tmp which is actually a disk in memory. Thus, your SD card won’t get touched so often.

You are done, congratulations!

Second the installation of a Minecraft PE server

Since minecraft servers need quite a lot of power and memory, it is wise to install this server on a separatye Raspberry PI.

I Assume you have a working Raspberry PI with SSH working. The website I used as basis for this information uses a very basis version of Raspbian. I used the standard version and that works as well.

Start SSH session or a terminal.

mkdir nukkit cd nukkit

wget -O nukkit.jar http://ci.mengcraft.com:8080/job/nukkit/lastSuccessfulBuild/artifact/target/nukkit-1.0-SNAPSHOT.jar

sudo java -jar nukkit.jar

You’ll be able to choose your language from a list of options preceded by “[INFO].” Type the indicated three-letter code and hit enter to choose a language.

I’d recommend English.

Now you’ll get a few lines of information preceded by that same [INFO] tag. If you did it right, you’ll see lines like “preparing level ‘world'” and, hopefully, “Done!” with some information about how long the game took to start.

By default, your server will be a survival server. I’ll show you how to tweak that in the final section.

Okay, let’s play! Grab your phone, tablet, or whatever else you’re running Minecraft Pocket Edition on, and start Minecraft.

Make sure you’re on the same Wi-Fi network as your server. Now hit play and head to the Friends tab.

Your server should appear under LAN Games.

Edit server.properties:

You can do all kinds of stuff by tweaking the server.properties file. Here’s the command you’ll need to edit the file:

sudo nano server.properties

Minecraft’s Gamepedia page has the details on all the things you can change, so I’ll let you click the link for the details and will just briefly mention two important settings:

gamemode starts at 0 (survival) and can be changed to 1 for creative, and difficulty starts at 1 (easy) and can be raised as high as 3 or lowered to 0 for peaceful.

Edit Nukkit’s configuration file:

Nukkit has a config file of its own, too. Most of your game-related options are in the other one, but you can tweak things like the number of chunks loaded in this file, which can be reached with the command sudo nano nukkit.yml

Run the server headless

Now we want to have the server working even if the terminal isn't open of even if we don't have a SSH session open.

To do this we need to install some packages.

sudo apt install netatalk screen avahi-daemon

We need to make a startscript:

nano minecraftPE.sh

and write the following four lines of code:

if ! screen -list | grep -q "minecraftPE"; then cd /home/pi/nukkit screen -S minecraftPE -d -m sudo java -jar nukkit.jar

fi

The if clause helps to make sure that only one instance runs at any one time (it is not perfect, but should be good enough).

Some people have trouble copying and pasting the content of the minecraft.sh file. As a sanity test, type

wc -l minecraftPE.sh

The shell should return 4 minecraftPE.sh indicating that the script has 4 lines, if you do not see the number 4, do not continue! If you get any number other than 4, then you did not correctly copied the script, it will not work. I am aware that your browser might represent on the web page the 4 lines as more than 4 lines, but there are exactly 4 lines to be copied.

We also want to check the syntax of the script, so type

bash -n minecraftPE.sh

this command should return immediately without any error. Now that we have verified that the script has four lines and has a valid syntax, let us make the script executable:

chmod +x minecraftPE.sh

We want the server to start automatically when the Raspberry Pi reboots, so type

sudo nano /etc/rc.local

and enter

su -l pi -c /home/pi/nukkit/minecraftPE.sh

right before the exit command.

Access your server online:

These instructions have given you a local server, but you can make this an online server if you so desire. You’ll just need to set up port forwarding on your router. Grab a computer and access your router’s settings page by typing in your router’s IP address (it’s probably on the router, and you can always use Google to track down your router brand’s default IP). Forward port 19132 (that port number comes from server.properties) to your Pi’s local IP address. If you do this, you should be able to enter your public IP to connect to your server from outside of your local network.

Activate SSH:

You may find it easier to control your server from a computer via SSH – that way, you don’t have to leave a monitor and keyboard and all that connected to your Pi the whole time. You can allow SSH in the raspi-config menu (Advanced Options > SSH).

For more on how to SSH into your Raspberry Pi, check out our article titled (what else?) How to SSH into the Raspberry Pi.