Raspberry Pi Minecraft Server Setup Script w/ Startup Service

Minecraft 1.16 Nether Update
Minecraft 1.16 Nether Update

***UPDATE 10/19/2020 – Minecraft 1.16.3 is here! PLEASE make sure you have full backups of your server before attempting to upgrade your server. If you read the older comments you will see that weird things can happen with version upgrades sometimes. 1.15 was an absolute mess at first and a few people without backups in the comments wanted to roll back and had some serious regrets.

1.16.3 has been a very stable experience and is working well. It’s safe to upgrade as long as you’ve made backups!
***END UPDATE

Minecraft 1.16.3 (Nether Update) is here! This script and guide are written to help you get a great performing Raspberry Pi Minecraft server up and running in only a few minutes.

Features

  • Sets up fully operational Minecraft server in a couple of minutes
  • Raspbian / Ubuntu / Debian distributions supported
  • Installs and configures OpenJDK 11 (or higher if available)
  • Sets up Minecraft as a system service with option to autostart at boot
  • Automatic backups to minecraft/backups when server restarts
  • Updates automatically to the latest version when server is started
  • Easy control of server with start.sh, stop.sh and restart.sh scripts
  • Optional scheduled daily restart of Pi using cron
  • Optional configuration of video memory to 16MB (default 64MB) and overclocking MicroSD reader to 100Hz (default 50Hz) for maximum performance

Requirements

  • Raspberry Pi model with 1 GB of RAM or higher. Basically a Raspberry Pi 2B or higher. (No Zero unfortunately, 512MB is not enough RAM to do this, I’ve tried!)
  • Headless Linux distribution such as Raspbian Buster Lite, Ubuntu Server 18.04.2, or any Debian based distribution (GUI distros can be used at the expense of available RAM and server performance)
  • Solid state drive highly recommended but not required.
    You can get a SSD setup on a Pi for less than most Micro SD cards cost. See my article here for details
  • If using MicroSD you want to be using a high range card otherwise you will really be hurting on IO when the server is reading/writing chunks of terrain! Click here for MicroSD card benchmarks/recommendations.

Recommended Gear

Raspberry Pi 4 Model B *8*GB*

Raspberry Pi 4 8GB

StarTech 2.5″ SATA to USB 3.0 Adapter* -AND- Kingston A400 SSD 120GB SATA 3 2.5” Solid State Drive*

StarTech 2.5" SATA to USB
Kingston A400 SSD

Or for a compact setup: SanDisk Extreme Pro 128GB USB Solid State Flash Drive*

SanDisk Extreme Pro 128GB USB SSD

Best benchmarking Micro SD card: SanDisk Extreme 64 GB MicroSD Card*

SanDisk Extreme A1 MicroSD Card

Choosing a Linux Distribution

The most important consideration when choosing which flavor of Linux to run the server on is simple: available RAM. Headless Linux distributions such as Raspbian Lite that don’t have a built in GUI have

Our biggest obstacle when running a Minecraft server on the Pi is available RAM since 1 GB is extremely low for this type of server. To have a playable experience you should not be running anything else on the Pi so all memory is available to be used.

After testing on many different distros I am finding Raspbian Lite and Ubuntu Server 18.04.4 32-bit to be the best choices. These distributions come with very few background processes and have rock solid support and performance.

64-bit vs 32-bit

There’s a lot of discussion in the Pi world about the up and coming aarch64 64-bit distributions vs. armhf 32-bit distributions. They have been and continue to improve dramatically. There are already use cases where 64-bit is far superior such as video encoding, advanced compression, etc.

So how about for running a Minecraft server? I have been testing extensively with Ubuntu Server 18.04 64-bit and the Debian Buster 64-bit. I have consistently had worse performance and stability than on 32-bit versions of the exact same distros.

But how can that be? It’s certainly true that Minecraft servers benefit in CPU performance from 64-bit versions of Java. The answer is actually incredibly simple: memory. The server running on a 64-bit Java Virtual Machine uses a minimum of about 100 MB more memory. This makes perfect sense because 64 bits > 32 bits by definition!

The Raspberry Pi’s 1 GB of memory has been the biggest obstacle for this project since the very beginning. Back when I first went into the Paper Minecraft developer IRC room and told them what I was trying to do I was practically laughed out of the chat room for even thinking of trying this. Most Minecraft server branches including vanilla can’t even start on the Pi because of the limited memory.

For a dedicated Minecraft server on the Pi I very highly recommend staying 32-bit. You will have more available memory which means it will be much faster and more stable. Since memory is our bottleneck the increased CPU throughput does not help us and losing *any* of our memory is disastrous!

If the Raspberry Pi 4 has more memory like we all expect it to this recommendation will change completely. Even 2 GB of memory would make the extra memory that 64-bit uses a non-issue and the CPU throughput performance gains very desirable. For now though stay 32-bit for a Minecraft server!

Tested Distributions

Raspbian Lite – It’s Raspbian. It has very low memory usage and is the official distribution of the Raspberry Pi. The server runs very well on this. It’s overall the best choice. The Buster release has made OpenJDK 11 available on it so it’s no longer behind the rest of the distros.

Ubuntu Server 18.04.3 – Ubuntu Server is my favorite Linux distro. I use it for nearly all of my projects. The performance of the 32-bit armhf version is on par with Raspbian. It’s a great choice! Click here for my Ubuntu setup guide for Raspberry Pi. The 64-bit version is not a fantastic choice and not recommended because of the higher memory usage. Stick with 32-bit and you’ll be a happy camper with Ubuntu Server.

Debian Buster 64-bit – Debian is the distribution Raspbian is based on. This version is a preview of Debian “Buster” which is the successor to Stretch and will be the next version of Raspbian when it is released. I like this distribution but it is currently still unofficial and unsupported. Performance and stability was less than Ubuntu and Raspbian.

Benchmark Your Storage

Make sure your storage is running fast enough to be an effective Minecraft server. I wrote a benchmark for this purpose to make this extremely easy. To get accurate results make sure nothing is running when the benchmarking is taking place.

Run the benchmark by pasting/typing:

sudo systemctl stop minecraft
sudo curl https://raw.githubusercontent.com/TheRemote/PiBenchmarks/master/Storage.sh | sudo bash 

Ideally you will score around 1000 for a good quality Micro SD card (and much higher for solid state storage). A low score (< 700) here indicates here that it is probably time to upgrade to a solid state drive or a faster Micro SD card. Click here to view all the existing benchmarks.

You can still run the server if you’d like with a low storage score but be advised when operations like saving the server’s blocks take place the people online may experience quite a big of lag!

Installation

SSH into your Raspberry Pi and paste the following commands:

wget https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh
chmod +x SetupMinecraft.sh
./SetupMinecraft.sh

The script will setup the Minecraft sever and ask you some questions on how to configure it. I’ll explain here what they mean.

“Enter amount of memory in megabytes to dedicate to the Minecraft server” – The amount of memory that will be dedicated to the Minecraft server. The more the better, but you must leave some room for the operating system background processes.

If you exceed the total available memory either the server will crash or the Pi will get incredibly slow to the point where your SSH session will start timing out. The setup script will make a recommendation to you which is your available memory – 10% for headroom. If you aren’t sure what to put just go with the recommended amount.

Note for Raspberry Pi 4: Currently on 32-bit Raspbian 2700 MB is the maximum that Linux will let us allocate in a 32 bit environment. The script has been updated to check for this as the server will not start if it is set over 2700M on a 32 bit server. 64 bit operating systems will be able to allocate all available memory as Pi 4 support rolls out for them.

“Start Minecraft server at startup automatically (y/n)?” – This will set the Minecraft service to start automatically when your Pi boots. This is great because whenever you want to play you can just plug it in and go without having to SSH in.

“Automatically reboot Pi and update server at 4am daily (y/n)?” – This will add a cron job to the server that reboots the Pi every day at 4am. This is great because every time the server restarts it backs up the server and updates to the latest version. See the “Scheduled Daily Reboots” section below for information on how to customize the time or remove the reboot.

That is it for the setup script. The server will finish configuring and start!

Check Java Version

Sometimes if you have multiple versions of Java installed the wrong version of Java will be selected as the default. If the server didn’t start check that the right version of Java is selected with this command:

sudo update-alternatives --config java

If you get the message “update-alternatives: error: no alternatives for java” then you only have one version of Java installed and can skip to the next section.

If you are presented with a list of choices then your machine has multiple versions of Java installed. It will look like this:

update-alternatives: warning: /etc/alternatives/java has been changed (manually or by a script); switching to manual updates only
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

You will usually want to just select the newest version of OpenJDK that is listed so you would type 0 and press enter. In some cases on some platforms you may want to switch to the official Oracle JDK although I strongly recommend sticking with OpenJDK!

First Run

The first time you run the server it will take a little longer to start since it is generating all the server data. If you try to log in before it fully starts you will get a connection timeout error. Watch for the line: “Timings Reset”. This is the last line that prints when the server is ready to rock and roll. At this point you will be able to connect successfully.

The very first time you log into the server it will be slow for about 1-2 minutes. This is because since nobody has logged in before the server has to scramble to generate all the chunks within your view distance (10 by default) and send them to you/store them. During this time you may not be able to see very far and if you try to destroy blocks there will be noticeable lag from when they break to when they actually disappear.

Don’t panic! This will go away within a couple of minutes as the Pi catches up with all the first time login stuff it needs to do. Performance stabilizes and it will feel very much like the offline experience after that.

If you are hosting for a few friends I’d recommend logging in for the first time right after you set up the server instead of having several people nail a blank server at first startup. This gets it out of the way and when everyone is ready to log in the starting area chunks will be fully fleshed out and the Pi just has to read them. It’s an order of magnitude faster for the Pi to read chunks than to generate and store chunks.

In my experience after the initial login exploring new parts of the server doesn’t cause any lag even though new chunks are being generated. The reason for this is that when you’re walking it’s really only having to generate a new chunk as you get close to the border instead of a huge square area of chunks in all directions and all at the same time like during the first login.

Changing Minecraft Server Version

If you want to change which version your Minecraft server is running it can be changed by opening SetupMinecraft.sh with any text editor (example: nano SetupMinecraft.sh).

Change the line Version=”1.15.1″ to whichever Minecraft server version you want to run. Note that that version must already exist for Paper Minecraft. You can view all available versions at the following URL:

https://papermc.io/api/v1/paper/

Changing Minecraft Client Version

If you are wisely running the “stable” branch instead of the “development” branch there will be times where you need to select the version of Minecraft to run otherwise you will get an error message that your client is outdated when you try to log in.

Fortunately this is very easy. Open up the Minecraft launcher and instead of hitting “Play” choose “Launch Options” in the menu at the top of the window. It will look like this:

Minecraft launch options
Minecraft Launcher “Launch Options” Tab

Click the “Add new” button and pick which version you want to add. You can optionally gave it a name or just click save.

Now when you go back to the “News” tab you will see a dropdown arrow where you can select which version of Minecraft you want to play!

Start, Stop and Restart Server

The server can be started, stopped and restarted two different ways. You can use the provided scripts in the Minecraft folder or you can use systemctl. Here are the commands:

cd ~/minecraft
./start.sh
./stop.sh
./restart.sh

-OR-

sudo systemctl start minecraft
sudo systemctl stop minecraft
sudo systemctl restart minecraft

Automatic Backups

The server backs up each time it starts. This helps you recover easily if something goes wrong. This system works best if you configured the server to restart daily since it means you will have a backup every day.

To access these backups type:

cd ~/minecraft/backups
ls

When a backup is made the filename will be the date and time the backup was taken. If you need to restore a backup it’s very easy. Substitute the timestamp in my example to the backup you want to roll back to. Type:

cd ~/minecraft
./stop.sh
rm -rf world world_nether world_the_end
tar -xf backups/2019.02.15.22.06.30.tar.gz
./start.sh

Your world has now been restored! It’s a good idea to download these backups off the Pi periodically just in case the Pi’s storage fails.

Scheduled Daily Reboots

The daily reboots are scheduled using cron. It’s very easy to customize the time your server restarts.

To change the time that the server restarts type: crontab -e

This will open a window that will ask you to select a text editor (I find nano to be the easiest) and will show the cronjobs scheduled on the Pi. The Minecraft one will look like the following:

0 4 * * * /home/ubuntu/minecraft/restart.sh
cron options

There are 5 fields here. The default restart time is set to reboot at 0 minutes of the 4th hour of the day (4 AM). The other 3 fields are left as * to represent every day of every month. Make any desired changes here and press Ctrl+X to exit nano and update the cronjob.

To remove the daily reboot simply delete the line and save.

Installing Plugins

The server supports plugins that are compatible with Bukkit / Spigot / Paper. A popular place that you can get plugins is at where there are thousands of them!

To install a plugin you simply download the .jar to the minecraft/plugins folder and restart the server. For example, WorldGuard is a very popular plugin that lets you add protection to different areas of your server.

To install this plugin on our Minecraft server we would use the following commands:

cd ~/minecraft/plugins
wget https://dev.bukkit.org/projects/worldguard/files/latest
sudo systemctl restart minecraft

The server will restart and the plugin will be installed. It’s that simple! To use the plugin refer to the documentation on the plugin download page to find out which commands you use to configure/interact with it.

Warning: be advised that plugins are the #1 issue for performance degradation on Minecraft servers. This isn’t because all plugins are bad. Some plugins are coded very inefficiently or perform features that require a lot of hooks in the code.

You should be careful about what plugins you install on the server and if you start having bad performance disable your plugins one by one until you find the culprit!

Reconfigure / Update Scripts

The scripts can always be reconfigured and updated by downloading the latest SetupMinecraft.sh and running the installer again. It will update all of the scripts in the Minecraft directory and reinstall the startup service for you.

Running SetupMinecraft.sh again will also give you a chance to reconfigure options such as the memory dedicated to the server, daily reboots, starting the server on boot, etc.

This will not overwrite your world or any other data so it is safe to run!

Port Forwarding

If everyone on your server is on the same LAN or WiFi network as you then you don’t need to do this. If you want people to connect from outside your local network then you need to set up port forwarding on your router.

The process for this is different for every router so the best thing to do is just look at your router and find the model # and put that in google with port forwarding for easy instructions on how to do it for your specific router.

You want to forward port 25565. The type of connection is TCP if your router asks. Once you do this people will be able to connect to your Minecraft server through your public IP address. This is different than your local IP which is usually a 192.x.x.x or 10.x.x.x. If you don’t know what that is just go to google and type “what’s my ip” and Google will kindly tell you!

Wired vs. Wireless

Going with an ethernet (wired) connection is going to be faster and more reliable. There’s so much wireless traffic and other interference in the air that running your server on WiFi is not recommended.

Even if it is working great 99% of the time it can ruin your experience very quickly if the WiFi drops for a couple of seconds and you get blown up by a creeper!

All that being said, the server works fine on wireless. The script will work fine as is with a wireless connection.

Upgrading

PLEASE BACK UP YOUR SERVER FIRST! The server makes automated backups by default for you in the backups folder but I recommend you back up the entire server folder yourself (basically the entire minecraft folder) any time you attempt to upgrade or downgrade. If you need to roll back to older versions it won’t work without a backup from that version or older!

The easiest way to upgrade an installation is to download the latest SetupMinecraft.sh and run it. This will automatically upgrade you to the latest version.

Upgrading and downgrading to versions that aren’t the default the script chooses is pretty simple. Simply change the Version line at the top in the SetupMinecraft.sh script:

#!/bin/bash
# Minecraft Server Installation Script - James A. Chambers - https://jamesachambers.com
# More information at https://jamesachambers.com/raspberry-pi-minecraft-server-script-with-startup-service/
# GitHub Repository: https://github.com/TheRemote/RaspberryPiMinecraft

# Minecraft server version
Version="1.16.1"

Edit this file in your favorite text editor (you can use nano or vi on the Pi like nano SetupMinecraft.sh) and change the Minecraft version to what you want.

Downgrading

PLEASE RESTORE USING A BACK UP FROM THE VERSION YOU ARE DOWNGRADING TO

If you are having problems on a newer version of Minecraft and want to downgrade you can do so using a complete backup of your server before you ran it on a newer version.

The reason you can’t take server data that has been touched by a version such as 1.16.1 and go back to 1.15 is that the new version adds all sorts of new data types/structures for the new content into your server data files. If you try to roll back the old versions of the Minecraft server will not understand these data types since they didn’t exist in that version and will crash.

As long as you use a backup for your server files from that version (or older) it’s as simple as changing the version in SetupMinecraft.sh just like I show in the “Upgrading” section.

You can upgrade any old version of Minecraft to any version, but again make sure you have a backup first as it is a one way street and you will need that backup if you want to roll back!

Version History

To view the version history check out the GitHub README here:

https://github.com/TheRemote/RaspberryPiMinecraft#update-history

510 thoughts on “Raspberry Pi Minecraft Server Setup Script w/ Startup Service”

  1. Avatar for Michael

    The only script that works for me is the SetupMinecraft.sh, so I have to run that everytime. Also where is the world that the Setup script located? I have a world folder in that minecraft folder but that server launches with a different world and I’d like to back it up.

    1. Avatar for jamesachambers

      Hey Michael,

      The name of the folder will be what is in your server.properties. By default it will be world. It’s determined by this line here:

      level-name=world

      It’s going to use whichever folder you have in there. It will also create two other folders named world_nether and world_end depending on your server label for “The Nether” and “The End” if you were using the Spigot/Paper server on Windows instead of vanilla. This can make the folder it’s using a lot easier to spot but for a definitive answer (even on servers that were running on vanilla) check server.properties.

      Change this line to the right world folder that you want to load. You could also just rename your folders, but I would just change the level-name=world line in server.properties to match what you were already using before. You should be able to find what it is using in there now under level-name= from your old server.properties as well. Hopefully this helps!

      1. Avatar for Michael

        I’m trying to find where the world folder that the setup script creates is located, since that world folder that it’s there is a different one. Wanted to know how to back it up.

        1. Avatar for jamesachambers

          It creates a backup each time you start the server in the backups folder. There should be a bunch of copies in there if you have been using it for a while. Going in there and pulling a copy with a date from before you attempted to try and merge anything should be the old original world folder.

          It will only use the “world” folder unless you’ve changed level-name= in properties. If the world that is in the world folder is not the right world then it got replaced and you will need to go to the backups. If you overwrote or copied over the old world folder this would happen for example. It’s not stored in a separate/special location. It’s just the defaults.

          I would back up everything you are doing before you do anything else. Take a full backup of the ~/minecraft folder as a snapshot before making any more changes. We haven’t located the old world you want to back up so it’s not ready for a merge yet. It sounds like you may have already overwrote parts of your server. Before you do anything else take a copy of everything!

          I apologize if you already did this in advance and have full backups, but I wanted to add this in case anyone else is reading this later and attempting this. Backups backups backups, you WILL make mistakes especially if you’ve never done this before, or even if you’re a seasoned vet, even I still do!

          1. Avatar for jamesachambers

            So whatever technical issue the server is giving you is not important here. All that matters is do you have the server backup files for BOTH servers? Did you check the backups folder? If you overwrote the world folder and nothing is in your backups folder somehow then it’s unfortunately gone.

            You can always delete the ~/minecraft folder (making sure you have backup copies of the entire folder (everything) before you do this) and set it up from scratch and restore the world folder from the backup of the server you want to use. This is the normal process for restoring backups (in the guide for a reference on the steps) and what I would definitely try. I would not try to bother fixing whatever is wrong with that merged setup. It’s not meant to be merged with different worlds occupying the same folder or anything like that.

            I’d delete it and restore it from one of the backups and it should take care of it! Trying to fix/troubleshoot this will not make sense when it will only take a few minutes to restore it from a backup!

            1. Avatar for Michael

              I had an old server that was also named world, accidently made this one cause I thought we lost the 1st one, so we made the 2nd one. Now the Setup.sh loads up the 2nd world and I want to backup this one but if I copy it over it’s the 1st one.

              The backups folder only backed up the 1st world and not the one we’re on right now.

              1. Avatar for jamesachambers

                Hmmm, thanks for the additional information!

                Are you running SetupMinecraft.sh as sudo? If you are (I thought I put in a check to not allow that, but maybe I did Bedrock and not this one yet) then I think I might know what is happening.

                Can you type:

                sudo su
                cd /root
                ls

                and see if you see a Minecraft folder? If you do then what is happening is you are running the server as root instead of a regular user. This means that the server files in your ~/minecraft folder wouldn’t get used. It would be /root/minecraft instead.

                If this is what is happening then the files just aren’t where we expected them to be but at least that will be where all of your 2nd server backups would be (in /root/minecraft/backups).

                  1. Avatar for jamesachambers

                    Got it. That seemed like it had to be it!

                    Your server should have backups of both the old and new server. It doesn’t make sense that every backup would only be the first server. Have you restarted it? Every time it restarts it should create a new backup.

                    So you’d have a bunch of older backups and then at one point when you switched over to the new server the backup files would start to contain the new world. Where are these backups going? Are there any other users setup on the Pi?

                    What folder does it say it’s running in if you do:

                    sudo nano /etc/systemd/system/minecraft.service

                    I have:

                    [Service]
                    User=pi
                    WorkingDirectory=/home/pi/minecraft

                    The backups have to be going somewhere. If the new server backups are not present in the folder (unless it has literally never been restarted yet) then we must not be looking in the right one! This would make sense with you having to use SetupMinecraft.sh to even start the server.

                    Unless…. you were also having permissions issues. Have you tried a

                    sudo chown -R youruser ~/minecraft

                    yet? Maybe it can’t even write the backups!

                    1. Avatar for Michael

                      It’s going to the minecraft folder as well, but that’s also where the 1st files were, but I have restarted the server since it has made backups but only of the 1st server.

                    2. Avatar for jamesachambers

                      Well you could always just backup the current “world” folders here since the server has to exist somewhere and presumably those are the right ones.

                      You can also search with something like:

                      sudo apt install mlocate -y
                      sudo updatedb
                      sudo locate level.dat

                      This will look for level.dat files which will be in each type of world folder.

                      If the server exists and you can log onto it/restart it then it has to have files somewhere. Mine looked like this:

                      pi@raspberrypi:~/minecraft $ sudo locate level.dat
                      /home/pi/minecraft/world/level.dat
                      /home/pi/minecraft/world/level.dat_old
                      /home/pi/minecraft/world_nether/level.dat
                      /home/pi/minecraft/world_nether/level.dat_old
                      /home/pi/minecraft/world_the_end/level.dat
                      /home/pi/minecraft/world_the_end/level.dat_old

                      Those are the only world folders in play on my machine. If you see the same then those have to be your second world files and you can just zip them up or back them up however you’d like. I’d try backing it up that way and then restoring it and make sure it works first and if it does I would wipe your entire setup and do it from scratch with a backup restore. That should eliminate having to run SetupMinecraft.sh every time to start it which is definitely masking some sort of major problem here.

                      They *have* to exist for it to be possible for you to restart it. If those are the only ones I would definitely recommend double checking that that it is in fact restoring the first worlds files. It’s absolutely impossible for them to not exist anywhere! The automatic backup could just be broken from whatever is wrong that is making you have to run SetupMinecraft.sh. If this is the case then just manually backing up those world folders should do the trick!

  2. Avatar for J.D.

    Hello James,
    I didn’t know if my comment posted or not so I am trying again. Sorry if it is a double.

    I was wondering how I could if possible to move the server world from one device to another.

    I have tried to move just the world, world_nether and world_the_end folders over and the server tries to start. I go to screen -r minecraft and it tries to load then a bunch of red error lines come up and terminates the screen. I then tried to rename the world folders to smp just to be something different similar to the change minecraft server world video on a pi and changed the server.properties file to the world name=smp. Still didn’t work.
    Log shows as follows:
    [19:46:15] [main/INFO]: Environment: authHost=’https://authserver.mojang.com’, accountsHost=’https://api.mojang.com’>
    [19:46:16] [main/FATAL]: Failed to start the minecraft server
    java.nio.file.AccessDeniedException: ./smp/session.lock
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116) ~[?:?]
    at sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:182) ~[?:?]
    at java.nio.channels.FileChannel.open(FileChannel.java:292) ~[?:?]
    at java.nio.channels.FileChannel.open(FileChannel.java:345) ~[?:?]
    at net.minecraft.server.v1_16_R3.SessionLock.a(SourceFile:37) ~[patched_1.16.4.jar:git-Paper-416]
    at net.minecraft.server.v1_16_R3.Convertable$ConversionSession.(Convertable.java:218) ~[patched_1.16.4>
    at net.minecraft.server.v1_16_R3.Convertable.c(Convertable.java:200) ~[patched_1.16.4.jar:git-Paper-416]
    at net.minecraft.server.v1_16_R3.Main.main(Main.java:113) ~[patched_1.16.4.jar:git-Paper-416]
    at org.bukkit.craftbukkit.Main.main(Main.java:276) ~[patched_1.16.4.jar:git-Paper-416]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:564) ~[?:?]
    at io.papermc.paperclip.Paperclip.main(Paperclip.java:58) ~[paperclip.jar:?]

    To me it looks like an authentication problem. Maybe the uuid.dat file?

    I don’t know if I should try to take a backup of the world I am wanting to keep and put that into the folder?

    Any advice would greatly be appreciated.

    I have 4 family members that play on it and the pi just isn’t keeping up as much as I would like so I took an old macmini I had laying around with 8GB of ram and installed ubuntu server on it and was able to get the minecraft server to install and run perfectly, just can’t seem to figure out how to get the world we have been playing on the pi over to the macmini.

    1. Avatar for jamesachambers

      Hey J.D.,

      That looks like a fairly common permissions problem. Here’s a reference. Did you copy the files over as root? The server only runs as your regular user so you actually don’t want to copy them as root or you want to fix them.

      You can set yourself as the owner recursively of the whole directory with this command:

      sudo chown -R youruser ~/minecraft

      Specifically it’s saying your server’s session file is locked (usually bad permissions or already in use) with this line:

      java.nio.file.AccessDeniedException: ./smp/session.lock

      You can copy the entire folder over. You just need to run SetupMinecraft.sh so that it adds my scripts into it that control it on the Pi. There is no difference between the server files on Windows and Linux. Java is always Java and runs on any platform with the same files that can support a Java Virtual Machine (JVM).

      There is a difference in how permissions work on Windows and Linux though and it sounds like these ones need to be tweaked to be owned by your username! Give that a try first and let us know if it goes after that. I don’t think it’s a bad copy or you’d be getting a lot uglier of messages but this one looks to be permissions related!

          1. Avatar for J.D. Goodson

            So I was still having a small issue with the server starting up on reboot even though I had permissions for the folder it would ask for a password to run ./start.sh. I had to do sudo visudo and add my username at the bottom with the no password to get it to work. It all works like a dream now.

            I did want to know how hard it would be to set it up as a bungeecord to run say survival and skyblock with a lobby. I know it would be basically 4 servers at one and each one with there own port number but I’m just wondering how it would do with reboots and getting them to start up at the right times.

            Any thoughts with that?

            1. Avatar for jamesachambers

              Hey J.D.,

              I actually remember someone trying this a long time ago and I think the issue they ran into was with memory at the time. Now with an 8 GB Pi I think it should be theoretically possible!

              I think you’ll be the first person to try it but I think it should work if you set some servers to a smaller amount of memory like for the lobby, etc. The main “meat and potatoes” servers should get the larger portions of memory.

              Definitely let us know if you try this, I’d be fascinated to find out how it works out!

  3. Avatar for J.D.

    Hello James, I was wondering how I could if possible to move the server world from one device to another without messing up. I have tried to move just the world, world_nether and world_the_end folders over and the server tries to start. I go to screen -r minecraft and it tries to load then a bunch of red error lines come up and terminates the screen. I am not able to see what the errors are. I was able to move all the files from plugins over but for some reason the world folders is what is giving it the issue. I don’t know if I should try to take a backup of the world I am wanting to keep and put that into the folder? Any advice would greatly be appreciated. I have 4 family members that play on it and the pi just isn’t keeping up as much as I would like so I took an old macmini I had laying around with 8GB of ram and installed ubuntu server on it and was able to get the minecraft server to install and run perfectly, just can’t seem to figure out how to get the world we have been playing on pi over to the macmini without it crashing.

    1. Avatar for J.D. Goodson

      I have also tried moving the whole /minecraft folder over and that wouldn’t even try to start the server so I know that isn’t the right way. x_x

  4. Avatar for Benjamin

    I am having an issue everything works fine but as soon as I attempt to connect to the server it encrypts and tries to but I get disconnected and then I try to run the screen -r minecraft with the output
    There is no screen to be resumed matching minecraft.

    1. Avatar for jamesachambers

      Hey Benjamin,

      That’s a little bit more unusual of one. It sounds like it’s crashing!

      Can you pull the log file out of the “logs” directory? Since the screen is getting closed the log is probably going to be the only way to see what is going wrong.

      I vaguely feel like I’ve seen this before but it was options related. Did you change any settings in server.properties, particularly compression threshold or anything like that? Is this default settings?

  5. Avatar for Ross

    the server crashed and I’m getting the following error:

    Exception in thread “AWT-EventQueue-0” java.lang.OutOfMemoryError: Metaspace

    before this he server kept stopping without any warning and without any crash report

    1. Avatar for jamesachambers

      Hey Ross,

      Usually people’s instinct when they get this error message is to turn up the amount of RAM allocated to the server when you run SetupMinecraft.sh. In this case though it’s misleading, it really means the OS doesn’t have enough memory to give the Minecraft server’s Java process what it asked for.

      The last couple of people I have spoken with in the comments having this issue ended up needing to turn the RAM/memory they were giving to the server DOWN. Why? Because what is actually happening on your system is that it’s not leaving enough memory for everything else.

      This causes processes to start being forcefully terminated, which is why you observed the behavior of it just shutting off without any graceful close, log messages, etc. The OS forcefully killed it because if it hadn’t the entire system itself was going to crash since it was too starved for memory to continue operating. It was either kill the process using up all the memory or have every single process and the system itself crash!

      You did at least get a Java OutOfMemory error message out of it which I’ve seen this happen without even getting that. The reason you got the message is that if the Minecraft server can get away with using less memory than you gave it in SetupMinecraft.sh it will. But you gave it permission to request up to the amount you put in SetupMinecraft.sh and after some server activity it finally did and the request was denied because there was nothing left to give it without compromising the system. Then it spit out that error and died! By turning down the memory you give the server in SetupMinecraft you’ve told the server not to try to request more than is going to be available which will prevent this conflict.

      Are you using this Pi for anything else or running any competing services? If you run the command ‘top’ is the server fighting for memory/cpu cycles with other things on the list?

      What is the memory size of your Pi and how much did you give it? I would try running SetupMinecraft.sh again and try giving it 200-300MB or so less than before and see if this stops this behavior for you!

      1. Avatar for Ross

        I have the 4gb Pi 4. I reduced the amount of RAM i was giving it and it works a treat now! Thank you very much for your reply 🙂

        1. Avatar for jamesachambers

          Hey Ross,

          Thanks for the follow up post! I think I need to lower the “recommended” amount of memory because this has been coming up a lot lately. I set the recommendation algorithm years ago and I’m guessing that Raspberry Pi OS requires a little bit more memory for itself now than back when I wrote that memory estimation algorithm.

          I’m very glad you found success!

    1. Avatar for jamesachambers

      Hey Josh,

      You can absolutely set a seed! Here’s how you do it:

      The file server.properties contains a line that will say level-seed= with nothing else after it. You simply place the seed here!

      If this is a brand new server it will have started once before you can set the seed. Here’s the trick: After the script has completed and launched the server for the first time go ahead and close it (or type ‘stop’ in the console) and shut it down completely. Now edit server.properties and place your seed in the file. Next delete the “world” folder (rm -rf world from inside the ~/minecraft/ folder or just delete it in a File Explorer window) that the server created and then restart it with sudo systemctl restart minecraft or you can use the start.sh script inside the folder.

      And that’s it, all chunks in the world folder will now generate using the seed you put in server.properties!

  6. Avatar for Matt

    Not sure what I am doing wrong – but I cannot connect to the server on my iPhone nor iPad. I get the Unable to connect to World message.

    Install seem to go fine and I get a prompt on the server:


    [11:50:41 INFO]: Preparing spawn area: 0%
    [11:50:42 INFO]: Time elapsed: 2016 ms
    [11:50:42 INFO]: Running delayed init tasks
    [11:50:42 INFO]: Done (34.555s)! For help, type “help”
    [11:50:42 INFO]: Timings Reset


    All devices and the server are on same wifi network.I can connect via iPhone to RaspberryPi using SSH (via Prompt app).

    Using Pi4 8GB.

    I have tried it with several different base OS.

    Currently testing the 64bit beta of Raspberry Pi OS as I wanted something simple to test and wanted to make use of the memory – 32bit OS seemed to have lots of performance related warnings appearing on the server.

    I have tried using the autoconfg tool on this page as well as following the performance guide.

    When I try to connect to the server – I see an animated ping graph which does not happen if the server is off.

    I have tried setting the port to 25565 and 19132 – but the prompt does say:

    [11:50:09 INFO]: Starting Minecraft server on *:25565

    Should this show the IP address of the server – of is * a valid wildcard?

    What else can I try?

    Any help ideas really appreciated – the server is a project I am building with my 8 year old as a birthday present and he is miffed we cannot get it to work!

    1. Avatar for jamesachambers

      Hey Matt,

      The iPad and iPhone use the Bedrock edition of Java. That would be the port 19132 but this is the Java server which the iPad and iPhone can’t use.

      I do have a guide for that version at https://jamesachambers.com/minecraft-bedrock-edition-ubuntu-dedicated-server-guide/ but it’s very slow on the Pi since they never released an ARM version of the Bedrock dedicated server.

      Sorry for the confusion! They have made it very confusing with the two different editions of Minecraft. Microsoft is *terrible* at naming things. Look at what they named the new consoles! The “Xbox Series X” instead of the “Xbox One X”. I wonder how many people got old gen Xbox Ones for Christmas when parents thought they got the new one!

      The best rule of thumb is PC only is Java, and everything else is Bedrock (Xbox, Playstation, Switch, iOS, Android, etc). There is a Bedrock client for Windows as well which is called “Minecraft for Windows 10 Edition” that can only be obtained through the “Microsoft Store” app.

      You can absolutely still give the Bedrock server a go on the Pi but since it’s emulation it’s quite slow. The Java one is the best for the Pi for sure (for now, the server is still in alpha, hopefully on release we will get the ARM version)! This has confused countless people over the years and even to this day I still sometimes have to do a double take!

    2. Avatar for D.

      I personally haven’t tried this (I don’t have any Bedrock clients) but you can try using Geyser MC (https://geysermc.org/) to allow access to your Paper MC server on your Pi from Bedrock clients (iPad/iPhone). Geyser can be used as a plugin for Paper (download the Geyser-Spigot.jar). With 8GB of memory you should be fine in running Paper with a plugin or two. There is a full setup wiki at: https://github.com/GeyserMC/Geyser/wiki/Setup

      Good luck, and I hope this gets the birthday gift fully working!

  7. Avatar for ragmaxone

    Hi!
    Great script! It works great… except for performance.
    I thought it was a problem with the drive — my SD card only got just above 700 points — so I bought a better one — 1400 points — and even prepared myself for the worse and bought a SSD — I had a USB 3 enclosure and got about 4500 points.

    Problem persists even with the SSD.

    Moving across the world is flawless, but breaking blocks is not: when I break a block, it stays in place for one more second and then fall, sometimes it even goes back in place and I have to break it a second time.

    How can I make it work? What could be the problem? (NB: I’m using a wired connection for both the client and the server).

    1. Avatar for jamesachambers

      Hey ragmaxone,

      You’re right, that’s way too slow! Which Pi are you using and how much memory does it have? Are you using Raspbian/Raspberry Pi OS? Is the Pi being used for anything else?

      Basically if you took a 4GB to 8GB Pi and imaged it with the latest Raspberry Pi OS and then installed the script it should not have a block break delay like this. When I was playing with some friends on a server a few months ago I used a SD card for the first few weeks and eventually upgraded to a SSD but at no point was it taking nearly so long to break blocks. When I was on the SD card when I first started up the server there would be a block break delay for like the first I would say maybe 60 seconds after the server started then it would go away completely.

      How much memory are you allocating for the dedicated server when you run the setup script? Depending on the memory size of this Pi you may need to use one without a GUI like Raspberry Pi OS Lite etc.

      1. Avatar for ragmaxone

        RPi4 with 4GB, latest Raspberry Pi OS from Raspberry Imager, 2700MB allocated — I’ll re-check tomorrow because I’m not if I didn’t leave the default value.
        The only thing running is a Hamachi VPN.

        The system was initially created on another SD card, I then made a backup and wrote it on both the new SD card and the SSD to try them.

        When I read about “the first 60 seconds” it came to my mind that it not a new world… could it be a problem that the world is from a server that initially run on Windows?

        I’ll try to switch to a new world and also kill Hamachi.

        1. Avatar for jamesachambers

          Hey ragmaxone,

          Thanks for the additional info! Your hardware configuration looks good to go with plenty of power and memory.

          If we are dealing with an existing server there’s some things to watch out for. Bringing a server over from Windows shouldn’t be a problem. The issues with existing servers we need to watch out for are:

          • Lag machines — certain monster farms / grinders, large and complex redstone contraptions, etc. can all cause lag
          • server.properties / spigot.yml / paper.yml – This script changes a bunch of configuration options on an initial setup to make it most efficient on the Pi. Some people also have their view distance cranked up which is going to impact the Pi as well. You could try keeping your existing server and just replacing the server.properties and the .yml config files temporarily with the default set my script creates as a test.
          • Very large server size – how big is the server and how old? If it’s huge just in raw size that could definitely be having an impact.

          There’s something else I’d like you to try. Sometimes SSDs and SD cards get slow like this if they need a “trim”. Can you try running the following command:

          sudo fstrim -av

          which will tell your Pi to run the trim command on all supported devices.

          The reason it can help is SD and SSDs don’t actually delete data when it’s removed from a drive and instead clear it before writing something new. This can have a horrific impact on server type applications (Minecraft server especially as it’s constantly reading/writing block/chunk changes) that a trim can help substantially with.

          The trim command tells it “delete this data now so it’s clear and you don’t have to do it during the write”. This may reduce your block delay time just from running this command. If it tells you it trimmed tens of gigabytes of data (or more) then you were likely being impacted by this to some extent, but there’s likely multiple factors at play here so this is just one piece.

          Disabling Hamachi temporarily as a test should be fine to rule it out. Maybe the service for it is using more memory than we think. If you monitor your system with the ‘top’ command how much memory is that process using? Does the server look like it’s fighting with anything else for CPU cycles / memory?

          If the source of lag is coming from inside the server we can test the TPS / performance inside the server with the Minecraft Timings tool. You may want to run the timings with the server running as that can often immediately point to the source of the lag if it isn’t hardware/resource/config related. I cover how to use the timings tool in this guide. It’s dated but should still be the same process!

          I’m interested to see what your fresh world test ends up yielding. That will narrow things down significantly!

  8. Avatar for William

    How do I open the minecraft lancher when I’ve downloaded it? It also seems as though the server never launches for me.

    1. Avatar for jamesachambers

      Hey William,

      You can use screen -r to resume the console and there’s also a “logs” directory if there are no screens logging that you can open the text file to get the error output! We can definitely help if you let us know what you’re seeing.

  9. Avatar for Chuck

    Having an odd problem. I got this running very quickly. Great tutorial. But…..port 25565 doesn’t appear to be open even though the mc server is running.

    I am on the same LAN so to eliminate port forwarding misconfigurations. I specified the IP of the wired interface in server.properties to keep it from trying to use the wifi.

    I telnet to port 25565 and get a connection refused and the MAC mc client times out as well. I don’t think iptables is the problem.

    1. Avatar for jamesachambers

      Hey Chuck,

      Are you able to pull up the server console with screen -r? Does it look like everything is running normally?

      Are you running regular Raspberry Pi OS or are you running a different distro? Some of them have firewalls enabled but if you are on Raspberry Pi OS then unless you installed UFW it’s not likely.

      You’ve ran some pretty good initial diagnostics. Not being able to make a connection on the port even with telnet tells us something is wrong.

      One other thing to watch out for is that if you fail to make a connection to a server once in the Minecraft client it will fail to connect forever until you restart it even if the server comes back up. I just wanted to mention this because as you’re testing make sure you are closing the Minecraft client completely out and then relaunching it from scratch before attempting to connect again.

      Are you able to the ping the IP address of the server?

      1. Avatar for Chuck

        Hello….so I can SSH into it remotely and ping so I have that connectivity. I wasn’t aware of that little quirk with the client because I was NOT restarting it after a failure. Even with doing so, no luck.

        Running Raspberry Pi OS:

        uname -a
        Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

        Update: Finally gave up on this at about 2a today and issued a reboot when I did it. It does seem that the server takes an inordinate amount of time to come up presumably being on a Pi3? I can now telnet to 25565 after waiting longer but, on a Mac and Windows 10 v1.16.4 of the client cannot connect.

        This is what screen -r minecraft shows and nothing seems amiss:
        System Info: Java 1.8 (OpenJDK Zero VM 25.40-b08) Host: Linux 4.9.35-v7+ (arm)
        Loading libraries, please wait…
        [04:20:20 INFO]: Environment: authHost=’https://authserver.mojang.com’, accountsHost=’https://api.mojang.com’, sessionHost=’https://sessionserver.mojang.com’, servicesHost=’https://api.minecraftservices.com’, name=’PROD’
        [04:20:24 INFO]: Found new data pack file/bukkit, loading it automatically
        [04:20:31 INFO]: Reloading ResourceManager: Default, bukkit
        [04:20:50 INFO]: Loaded 7 recipes
        [04:23:50 INFO]: Starting minecraft server version 1.16.4
        [04:23:50 INFO]: Loading properties
        [04:23:51 INFO]: This server is running Paper version git-Paper-354 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)
        [04:23:52 INFO]: Server Ping Player Sample Count: 12
        [04:23:52 INFO]: Using 4 threads for Netty based IO
        [04:23:52 INFO]: Debug logging is disabled
        [04:23:53 INFO]: Default game type: SURVIVAL
        [04:23:53 INFO]: Generating keypair
        [04:24:06 INFO]: Starting Minecraft server on 192.168.1.158:25565
        [04:24:07 INFO]: Using default channel type
        [04:24:08 INFO]: Server permissions file permissions.yml is empty, ignoring it
        [04:24:08 INFO]: Preparing level “world”

        1. Avatar for jamesachambers

          Hey Chuck,

          You’re right. It’s going really slow here. It took almost 3 minutes to load the data packs and get to starting the server! It also still wasn’t finished loading yet when you took that picture. It was right in the middle of loading the “world” or the map basically.

          How much memory did you give it when you set it up? The memory requirements are rising with each version. I haven’t ran it on a Pi 3 for a while, but you are going to want to set it to as close to max as you can get away with without it crashing!

          If it’s a 1GB you’d want to kill any background processes and preferably be running the lite version of Raspberry Pi OS or Ubuntu Server and see if you can get it to close to like 800MB allocated if you’re lucky. I haven’t done it for a while on a 1GB, so it may not be possible to give it even close to this much anymore, but I was able to hit this amount routinely a year or two ago.

          How much you can give will depend on how many background processes you can/can’t get rid of. If it’s a 512MB of RAM model it’s going to be tough these days. If it is one of those it would still help a lot to upgrade to a SSD! If this is a model with 512MB of RAM then running a server-only OS is going to be an absolute requirement. You’ll also want to set gpu_mem=16 in the /boot/config.txt file to only allocate 16MB of memory for video operations (the minimum).

          What storage device are you using? This is another common bottleneck. If you have a slower SD card it can definitely cause this. Have you ran my storage benchmark at https://storage.jamesachambers.com/? This is just a hunch after seeing these for a while. It’s taking a long time to load *everything* basically, even the stuff that shouldn’t which means the storage is likely bottlenecked here.

          1. Avatar for Chuck

            Got tied up on some other stuff over the weekend. Well I decided after your comments, looking at other things in the server and my own research that I just needed new hardware.

            Got a Pi 4B with 8GB RAM and 128GB SD card. Benchmark scored it at 1373 so we’ll see how that goes.

            Also using JDK v11.

            So now we do some testing and let my son and daughter beat on it for a while.

            1. Avatar for jamesachambers

              Congratulations Chuck! I think the 8GB Pi is a worthwhile upgrade.

              By getting USB 3.0 and much faster RAM clocks it’s a much bigger jump than the previous Pis were. You can also go 64 bit with 8GB of RAM!

              I’m sure the testing will go well! You could attempt a SSD upgrade if you’re not happy with where it’s at.

              I recently played with friends over a month or two on the SD card and didn’t have much trouble than right after reboots it would be slower to load back up and lag for the first minute or two then be fine.

              Definitely have fun and enjoy!

              1. Avatar for Chuck

                So far been working well … i tweaked some of the start up settings. The server seemed to have a tendency to crash and after looking through logs Java was running out of memory. Was running v11 and didn’t want to downgrade as that seemed counterintuitive. The recommended setting for memory was 2700MB. I backed it off to 2000MB and it seemed to have stabilized. Going to have fun taking this to the next level as I dig through your setup. This was really straightforward to setup once I got the right equipment. I don’t play minecraft but my kids and their friends do and now I get to teach them a little about a Linux operating system.

Leave a Reply to Dave Cancel Reply

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

Type here..