Raspberry Pi Minecraft Server Setup Script w/ Startup Service

Minecraft 1.17 - Caves and Cliffs Update
Minecraft 1.17 – Caves and Cliffs Update

Minecraft 1.17 (Caves and Cliffs 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.

This is the standalone version. It runs on most flavors of Linux and should work on most architectures as well (arm, aarch64, etc.).

I highly recommend using Docker over the standalone version for most people. Installing Docker is as simple as sudo apt install docker.io. There are 3 Docker options available:

It’s now possible to convert your worlds between Bedrock and Java versions. Check out my guide on Chunker here for more information.

Features

  • Sets up fully operational Minecraft server in a couple of minutes
  • Runs the highly efficient “Paper” Minecraft server
  • Raspbian / Ubuntu / Debian distributions supported
  • Installs and configures OpenJDK 18
  • 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

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

Minecraft Java for PC
Minecraft Java for PC / Mac / Linux*
Raspberry Pi 4
Raspberry Pi 4

The Raspberry Pi 4 is available in different memory configurations all the way up to 8 GB. It’s about the size of a credit card and uses an extremely low amount of power making it ideal for all sorts of projects and ideas!

Links: Amazon.com*, AliExpress*, Amazon.ca*, Amazon.com.au*, Amazon*.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.se*, Amazon.sg*

Raspberry Pi 400 Kit
Raspberry Pi 400 Kit

The Raspberry Pi 400 kit includes everything you need for a full Pi 400 desktop build. The Pi 400 is the fastest Raspberry Pi ever released and comes in the form factor of a keyboard!

Links: Amazon.com*, AliExpress*, Amazon.ca*, Amazon.com.au*, Amazon.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.se*, Amazon.sg*

Kingston A400 SSD
Kingston A400 2.5″ SATA SSD

The Kingston A400 has been a great drive to use with the Pi for years. It’s reliable, widely available around the world, has low power requirements and performs very well. It’s also very affordable. This drive has been benchmarked over 1000 times at pibenchmarks.com and is the #1 most popular SSD among the Pi community!

Links: AliExpress*, Amazon.com*, Amazon.ca*, Amazon.com.au*, Amazon.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.se*, Amazon.sg*

StarTech 2.5" SATA to USB 3.0/3.1 Adapter
StarTech 2.5″ SATA to USB 3.1 Adapter

The USB 3.1 variant of the StarTech 2.5″ SATA adapter works well with the Pi 4. The USB 3.0 variant doesn’t have firmware updates available and is not recommended.

Links: Amazon.com*, Amazon.ca*, Amazon.com.au*, Amazon.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.se*, Amazon.sg*

SD Card Setup:

SanDisk Extreme A1
SanDisk Extreme A1

The SanDisk Extreme A1-A2 SD card has the best scoring SD card on Pi Benchmarks for years and is second in popularity only to the SanDisk Ultra (often included in combo kits). The application class (A1) means random I/O speeds (very important when running an OS) have to meet a higher standard. There’s no benefit on the Pi for A2 right now so get whichever is cheaper/available.

Links: AliExpress*, Amazon.com*, Amazon.ca*, Amazon.com.au*, Amazon.co.jp*, Amazon.co.uk*, Amazon.de*, Amazon.es*, Amazon.fr*, Amazon.it*, Amazon.nl*, Amazon.pl*, Amazon.se*, Amazon.sg*

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

Raspberry Pi OS – 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 / 20.04 – 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.

Minecraft Server Installation

SSH into your Raspberry Pi and paste the following commands:

curl https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh | bash

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.

Benchmarking / Testing Storage

If you’re getting poor performance or just want to verify everything is working correctly you may want to run my storage benchmark with:

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

If you search for the model of your drive on pibenchmarks.com you can compare your score with others and make sure the drive is performing correctly!

Changing Minecraft Server Version

To override the default version let’s grab a copy of the script locally:

wget https://raw.githubusercontent.com/TheRemote/RaspberryPiMinecraft/master/SetupMinecraft.sh 
nano SetupMinecraft.sh

Now make these changes from inside nano:

Version="1.16.5" 
AllowLocalCopy="1"

Now press Ctrl+X to exit nano and answer “y” to save. Now let’s run the script:

chmod +x SetupMinecraft.sh
./SetupMinecraft.sh

And the setup will run and install the version of Minecraft you set at the top of the file!

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 Mods / Plugins

The server supports plugins that are compatible with Bukkit / Spigot / Paper. A popular place that you can get plugins is at dev.bukkit.org 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
curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.12.212 Safari/537.36" -o worldguard.jar https://dev.bukkit.org/projects/worldguard/files/latest
sudo systemctl restart minecraft

The reason the middle line is so long is that “robots” (roughly anything that isn’t a web browser being used by a user in this context) including scripts and utilities are blocked by the Bukkit server. The extra parameters we’re including in this line will add the location (-L) flag as well as a user agent and an identity / language header which will allow us to fetch the files without getting a 403 forbidden error.

Make sure to change “-o worldguard.jar” (second to last parameter) and the URL (very last parameter) to match the project you want to download.

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.17 and go back to 1.16 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!

Troubleshooting Note – Oracle Virtual Machines

A very common problem people have with the Oracle Virtual Machine tutorials out there that typically show you how to use a free VM is that the VM is much more difficult to configure than just about any other product / offering out there.

It is because there are several steps you need to take to open the ports on the Oracle VM. You need to both:

  • Set the ingress ports (TCP/UDP) in the Virtual Cloud Network (VCN) security list
  • *and* set the ingress ports in a Network Security Group assigned to your instance

Both of these settings are typically required before you will be able to connect to your VM instance. This is purely configuration related and has nothing to do with the script or the Minecraft server itself.

I do not recommend this platform due to the configuration difficulty but the people who have gone through the pain of configuring an Oracle VM have had good experiences with it after that point. Just keep in mind it’s going to be a rough ride through the configuration for most people.

Troubleshooting Note – Hyper-V

There is a weird bug in Hyper-V that breaks UDP connections on the Minecraft server. The fix for this is that you have to use a Generation 1 VM with the Legacy LAN network driver.

Version History

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

Update History – RaspberryPiMinecraft – Official GitHub Page

Other Resources

If you’re trying to set up SSD / USB storage booting check out my Raspberry Pi USB booting setup guide

For benchmarks and recommendations on the fastest storage drives/adapters for the Raspberry Pi check out my 2021 Storage Roundup

If you’re having firmware issues and need to update/restore your firmware check out my Raspberry Pi firmware guide here

1,106 thoughts on “Raspberry Pi Minecraft Server Setup Script w/ Startup Service”

  1. Avatar for Felix

    Hi James, I’ve been tryying to update my server to 1.18.1 with a fresh new world and all that but as the setup-script was finishing up and tried to start the server I got the error message “Must be connected to a terminal.” As far as I know I havent changed anything since my server was running before, what could have gone wrong?

    1. Avatar for James A. Chambers

      Hey Felix,

      It’s not too uncommon to get that message if things started up too quickly. Did you try typing screen -r? If it says there are no screens available then check the “logs” folder to see what is happening or type sudo systemctl status minecraft. If you are confused by the output go ahead and post it here and I will help if I can!

      1. Avatar for Felix

        ● minecraft.service - Minecraft Server Service
        Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; vendor preset: enabled)
        Active: failed (Result: exit-code) since Wed 2021-12-15 17:49:20 CET; 16h ago
        Process: 89253 ExecStart=/bin/bash /home/ubuntu/minecraft/start.sh (code=exited, status=0/SUCCESS)
        Process: 89322 ExecStop=/bin/bash /home/ubuntu/minecraft/stop.sh (code=exited, status=1/FAILURE)

        Dec 15 17:49:12 ubuntu bash[89253]: Latest paperclip build found: 76
        Dec 15 17:49:12 ubuntu bash[89295]: % Total % Received % Xferd Average Speed Time Time Time Current
        Dec 15 17:49:12 ubuntu bash[89295]: Dload Upload Total Spent Left Speed
        Dec 15 17:49:19 ubuntu bash[89295]: [711B blob data]
        Dec 15 17:49:19 ubuntu bash[89253]: Starting Minecraft server. To view window type screen -r minecraft.
        Dec 15 17:49:19 ubuntu bash[89253]: To minimize the window and let the server run in the background, press Ctrl+A then Ctrl+D
        Dec 15 17:49:19 ubuntu systemd[1]: Started Minecraft Server Service.
        Dec 15 17:49:20 ubuntu bash[89322]: Server is not currently running!
        Dec 15 17:49:20 ubuntu systemd[1]: minecraft.service: Control process exited, code=exited, status=1/FAILURE
        Dec 15 17:49:20 ubuntu systemd[1]: minecraft.service: Failed with result 'exit-code'.

        Thank you! This is what I am given when I enter what you gave me, when I try to enter the minecraft screen the pi tells me that there is no screen to resume, no matter How often I start or restart the server.

        1. Avatar for Felix

          Oh yeah and I assigned 6.8 GB of ram as I am running on the ubuntu 64 bit server edition thingy, I’ve tried with only 5 GB of Ram incase the 6800 were too much but it didnt change anything. Im running this all on a raspberry pi 4 8 GB.

          1. Avatar for James A. Chambers

            Hey Felix,

            It’s definitely failing to start. I would turn the memory to like 4GB or lower, it will easily run on less than 1GB and since yours is failing to start it’s much more likely it’s too much. Did you check the log folder to see what the server log files say? There’s nothing really in here, it’s trying to start normally but it’s not starting up so anything else is going to be in the real logs most likely.

            1. Avatar for Felix

              I’ve tried with 3.8GB and with 1GB, in both cases I still get the same message that there is no screen to be resumed.

              I’ve also tried to check for the logs but in the default /home/ubuntu/ directory there are none to be found, neither in the minecraft folder. I did find the /var/log/ folder but I couldnt quite make sense of which, if any, logs are relevant there.

              1. Avatar for Felix

                So, I’ve also tried setting it up from scratch with deleting the minecraft folder but I got the error that Java couldn’t be installed, I checked if I had the latest version and also updated just to be sure.
                Another thing I noticed while running the SetupMinecraft.sh script, is that I got the output:

                …(other stuff before this)
                Setup is complete. Starting Minecraft server...
                Must be connected to a terminal.
                Must be connected to a terminal.

              2. Avatar for Felix

                Sorry I keep forgetting things, I then checked the java version and selected the OpenJDK16 version that was on my pi. When I then ran the script again I didn’t get any error just the output that I pasted above.

              3. Avatar for James A. Chambers

                Hey Felix,

                The logs would be in ~/minecraft/logs for the startup. OpenJDK 16 should be fine.

                Is anything else running on this Pi? Is it up to date?

                You can try running it manually. Try running java -jar paperclip.jar from the minecraft folder and see what happens. It’s getting far enough though you should have logs for it so you shouldn’t see anything that isn’t in the log files but it’s definitely worth a try!

                The scripts are relatively simple here. There’s a few log files, there’s the systemd log, and then it just runs the jar. The script is just for convenience but it honestly sounds like your system is having serious problems. There’s really very little happening here related to running Minecraft and most of the code in the script has to do with backups and updates. The script should be able to set it up / run it on just about anything.

                If there’s nothing else being used on this Pi I would do a fresh OS install. Otherwise try running it manually and see what it’s saying that should definitely be in the ~/minecraft/logs folder as well unless it’s some sort of weird system crash. Maybe it’s Java related if you have multiple JREs/JDKs installed potentially (especially a really old one). Hopefully that helps!

              4. Avatar for Felix

                Big wall of text, easy solution… I was running Openjdk16 instead of 11. terribly sorry, thank you so much for the help anyways 🙂

              5. Avatar for James A. Chambers

                Hey Felix,

                No worries at all! I’m glad you found it and also left your solution for others. I seldom encounter stuff like this from the “developer” side as my machines always get filled with trash and then wiped fairly often so it’s really valuable to see what real-world problems outside of a development environment people are running into.

                Take care and come back if you run into any trouble, but it sounds like you’re off to the races!

  2. Avatar for Chris

    Hi James, could you comment on how to fix servers running your script against the Log4J-vulnerability? Minecraft itself have posted a hot fix here but I’m not sure this is applicable in this case. I guess best would be to release a new version of your script – I suspect you’re already onto this. Thanks!

    1. Avatar for Chris

      oh, excellent, you just upgraded the script to install 1.18.1., which I think fixes “Log4shell”. Any pointers about what to do if I still run 1.16.5?

      1. Avatar for James A. Chambers

        Hey Chris,

        Welcome, I was wondering when that log4j related vulnerability may come up here and you’re the first! Theoretically you should be safe but just make sure you have your backups saved outside of the “backup” folder before attempting. You should just be able to run SetupMinecraft.sh again!

        This is quite a version jump but I thought about it and I can’t think of anything that would have changed that would break this. I think you should be okay to run SetupMinecraft again to go to the latest here. Hopefully that helps!

        1. Avatar for Chris

          Thanks. Not sure why I should be particularly safe. Is it to do with the version of paper that is being used?

          Can stick with 1.16.5 at all?

          1. Avatar for James A. Chambers

            Hey Chris,

            The latest vulnerability has nothing to do with Paper at all. It’s actually even bigger than Minecraft itself (for Minecraft all versions above version 1.7 affected). It’s actually a log4j library vulnerability which is a tool that writes the Minecraft log files basically. You can read about it here.

            It’s extremely, extremely serious. People 100% pwned remotely just through the Minecraft client serious. Stuff like this is normally not actually possible (like having a port forwarded server is normally safe if you don’t forward any other ports and keep it patched/maintained, we are currently not in normal times and exploits are roaming wild for unpatched servers / servers lacking the config changes) and these types of exploits are extraordinarily rare. Given the popularity of Minecraft I have no doubt that there’s hordes of hackers roaming Shodan looking for vulnerable servers to go run whatever scripts they’ve come up with (or more likely downloaded from someone else) against to see what they can do / get.

            Only versions below 1.7 are not affected (yes, 1.7!). The safest option (and my recommendation) is to upgrade or try upgrading to 1.18.1 (even 1.18 is impacted). Keep backups before your upgrade and if you can’t stand it / it’s unstable / too much lag you can restore from backup on the old version and do the manual fixes.

            There is a link above with manual steps you can take to lock it down (and at the bottom of this message for the official Microsoft steps) if you want to stay on an old version. I’m not sure how Paper is going to specifically address this (if they will patch this fix into old versions or what) but if you aren’t going to upgrade I would do the manual fixes to protect yourself from the vulnerability. It’s pretty much just modifying some config lines to disable the features that allow this to happen.

            Here’s a montage of the vulnerability (< 1 min). Literally they just walk around on your server (from your perspective) and people are getting pwned (like hostile remote code executed on their machine silently levels of pwned) so it's pretty serious. For the longer version / breakdown here's a longer 16 min video about it.

            I’d say you can stick with 1.16.5 if you do the fixes but the recommendation is definitely to upgrade but if you’re confident / sure you’ve done the manual fixes correctly (or better yet test it yourself but this won’t be easy without any familiarity with how these type of exploits work) then this is absolutely possible. There’s a lot of room for error as you have to add flags to your Java Virtual Machine (JVM) which gets tricky because lots of machines have several JVMs and there’s one bundled which can get confusing as well. There’s a configuration file change as well. It’s nothing intense but it’s difficult to verify you did everything correctly with absolute certainty and the consequences if you didn’t are dire.

            I’m very uncomfortable giving the JVM flags and configuration changes a full-throated recommendation to everyone for likely the same reason as Microsoft though. You’re basically making a tiny config change in the Java configuration files. Are you sure you put it in the right place / for the right JVM / all of that? How would you be sure?

            You can verify your config files and verify your flags and that you changed the log4j entry and it’s being read/recognized but you need to actually do that and make sure. That’s the dilemma but if you do the fix correctly then it’s theoretically safe (unless more are discovered, but then even the patched version wouldn’t be safe from those). It’s definitely an option for advanced users who can be sure they did it correctly because if you’re wrong the YouTube videos will show you what will happen.

            If your server is accessible from the internet (you have a port forwarding entry set up on your browser and people don’t need to be on your LAN to play) then I would much more highly recommend upgrading. If your server is firewalled behind your LAN and only people at your house can play on it then I wouldn’t worry as much about this (although it’s still unsafe, if anything else on your network is hacked it is another target, but not in the same category of risk as having an internet port forwarded server unpatched from this which is insane). It’s so serious though that you really should lean on the side of caution on this one.

            Also check out the official Minecraft announcement about this vulnerability. They offer some files you can download to overwrite and tell you how to add a JVM argument to protect yourself (only necessary if you don’t want to upgrade to 1.18.1). It’s definitely worth a read as well.

            Hopefully that helps and gives you some options at least!

            1. Avatar for Chris

              Thanks. It looks serious. In my case the server is exposed to the open internet, so I guess I’ll say good-bye to 1.16.5 and upgrade!

              1. Avatar for James A. Chambers

                Hey Chris,

                No worries at all, I wanted to let you decide but I’m glad you’re going to secure it. If you don’t end up being able to use 1.18.1 let me know if you need any help restoring a backup. I’m guessing it will be okay though, definitely stop by again and let us know how it’s going!

  3. Avatar for briesenpap

    1.18.1 is out and somewhat stable (backups still recommended), follow the guide for the local copy of the script if you want to use it until James updates the server side script.

    1.18.1 clients work with 1.18 server which is the current default, but usually it is best to have versions aligned.

    James, as always big thanks for your work

  4. Avatar for Yui

    Hey there, your script is amazing and makes it such a breeze to get a server up for a few friends of mine. Thanks a bunch! 🙂 However, one particular issue I’m having is with a large world (around 3.6gb) is that the startup service fails as it is timing out trying to load the world (as well as the daily reboot). I’m assuming that an SSD will probably be the solution even though I have a Class 10 A1 sd, but is there anything you’d recommend in the meantime to remedy the behaviour?

    1. Avatar for James A. Chambers

      Hey Yui,

      It has been a while since this came up but there absolutely is an adjustment you can make for this. We will be editing the file /etc/systemd/system/minecraft.service. Type

      nano /etc/systemd/system/minecraft.service

      You should see a line like this:

      TimeoutStartSec=600

      Try changing that to 6000 to increase the timeout by 10x. Now press Ctrl+X to save the file from nano (or if you used a different editor that works too). Now type the command:

      sudo systemctl daemon-reload

      which will reload your service changes. That should get things going here!

      1. Avatar for Yui

        Hey James, thanks for the quick reply! 🙂 I should have realised this myself as I was testing the startup time quite a lot recently… anyways, it works a treat!

        It is surprising how large some Minecraft worlds get, even after playing for only around a month.

        Again, can’t thank you enough for the awesome script. Have a good day and Christmas (getting ever so close now).

        Kind regards,
        Yui

        1. Avatar for James A. Chambers

          Hey Yui,

          No problem at all, congratulations on having a server successful and big enough that this issue came up! There’s only a few other people that it has come up for.

          I’d like to add this as a configuration option somehow but it probably doesn’t make a lot of sense to have in the main installer. I wonder if I should make a options script of some kind with some special tweaks like this for more advanced/older servers as just a convenience script.

          At any rate, thanks for your kind words and I’m glad everything is working, enjoy and have fun!

          1. Avatar for deomaki

            Hi,
            unfortunately I have to join this discussion as well.
            First of all, congrats for your great work. I really appreciate it a lot! I have everything working for about a year now, but all of a sudden, since two weeks now, I am also experiencing the same problem: starting the minecraft.service always fails

            ● minecraft.service loaded failed failed Minecraft Server Service

            This is, as already stated by Yui, very unhandy regarding automatic updates of my papermc, power loss, etc…
            I have already changed the settings for TimeoutStartSec=600 to 6000 but with no effect (I suspected this not to work since I am using an SSD but tried it anyway, who knows…)
            The rest of in minecraft.service is exactly as in your reference (except user and paths, of course) 😉
            World is approx. 2.x gb
            HW setup as follows: Raspberry 4 8GB (still running 32Bit OS), Argon One M2, Kingston M.2 SSD A400 120GB
            Memory alloc is at -Xms512M -Xmx2048M
            As I already said: It ran perfectly until 29/11. Do you have any (additional) ideas?
            Kind regards
            Markus

            1. Avatar for James A. Chambers

              Hey deomaki,

              Yours sounds slightly different by the sound of it for sure. How long ago did you run SetupMinecraft.sh? I’m wondering if it was before I started adding a sudoers entry which could cause the restart to fail potentially.

              The most definitive way to figure it out though is to look at your logs during one of these incidents (~/minecraft/logs). It should give us a hint of what is going on. The other place to check is:

              sudo journalctl -xe

              These are the systemd logs (you may have to scroll down to find the minecraft related service but it’s in there) and they may give us a hint as to why it failed to start the service (sometimes this is logged here and nothing will be in the minecraft logs if it’s a systemd problem).

              Did you run the command:

              sudo systemctl daemon-reload

              after making any changes? This could potentially cause the service to fail to start as well if you change it and don’t update the daemons (by letting them know this is an authorized change on disk with the above command).

              I would also recommend just running SetupMinecraft.sh again and let it set up the service for you again. It’s totally safe* (make sure you have your backups moved out of the backup folder and stored safely before trying anything with the server for the totally safe part to apply) to run over the top of an existing install and that should fix it as well. Hopefully that helps and if you’re still stuck feel free to post some of the log entries and we’ll figure it out!

              1. Avatar for deomaki

                Hi James,
                thanks for your more than fast reply: three thumbs up…eh, wait… 😉
                I will go from bottom to top of your suggestions since the last time I ran SetupMinecraft.sh was around May this year…at least it was this year 😉
                And I think using the latest version of the setup script should not be a disadvantage as well 🙂
                And yeah, I ran sudo systemctl daemon-reload after changing the service – even doing a reload causes it to fail…
                So, I will run the setup again, do some amendments to start.sh (some additions regarding transfer of backups to my NAS) and will tell you my findings…maybe today 🙂
                Regards
                Markus

              2. Avatar for James A. Chambers

                Hey daomaki,

                That sounds good, and don’t forget to check your log files too! They are literally going to tell you what is going wrong. It would be something with your system most likely and not the script, especially if SetupMinecraft.sh can’t fix it but definitely check out the logs if you’re having trouble!

  5. Avatar for The Bit

    Hey James!

    Just want to thank you so much for your work! My friends and I are so excited for 1.18 and I was a bit worried that we wouldnt be able to play for a few weeks due to server updates. Checked the repo and bam its already updated!

    1. Avatar for James A. Chambers

      Hey The Bit,

      I was alerted by someone commenting here that the new version came out so I can’t take 100% credit for being that on the spot but I’m super glad it was there when you were ready to try it! Thanks for the kind words and take care / have fun!

  6. Avatar for Daniel

    Hi James! I used this guide to set up a server on my Pi 4 with 1.17 earlier this year. With 1.18 now out, how would I update my server to run 1.18?

    1. Avatar for James A. Chambers

      Hey Daniel,

      Make sure you grab your “backups” folder first (make some copies so you have them separate and they don’t get pruned during upgrades). Then you can just run SetupMinecraft.sh again. It will safely update you to 1.18 as that is now the default version of SetupMinecraft.sh. Hopefully that helps!

  7. Avatar for Mathew

    Hi, Had this runny for awhile now, awesome to be able to just type one command for us noobs, but this morning i went to play the 1.18 minecraft and noticed the server hadnt started. Tried manually starting but to no avail. Though i would do a fresh install, and now im getting error.

    error: unable to contact snap store
    error: unable to contact snap store
    snap "openjdk" is not installed
    update-alternatives: error: alternative path /snap/openjdk/current/jdk/bin/java doesn't exist
    update-alternatives: error: no alternatives for java
    main: line 243: [[: main: line 242: java: command not found: syntax error in expression (error token is ": line 242: java: command not found")
    main: line 243: [[: main: line 242: java: command not found: syntax error in expression (error token is ": line 242: java: command not found")

    Im not the best with these things so any suggestions would be great.

    1. Avatar for James A. Chambers

      Hey Mathew,

      Welcome back! It looks like there’s a problem with your snapd. It’s the “error: unable to contact snap store” and it’s having trouble getting OpenJDK. You may want to try reinstalling it with:

      sudo apt remove snapd
      sudo apt install snapd

      You should be able to do a sudo snap update as well. Can you give those a try? This is likely system related and that Pi might be ready for a reimage if you’re seeing anything else strange going on with the system. Let us know what you find!

      1. Avatar for Mathew

        Thanks for the reply. It seemed to be pihole blocking the connection for some reason. Disabled for a few minutes and its solved it. However new problems have arisen.

        1. Avatar for James A. Chambers

          Hey Mathew,

          I have disabled my PiHole recently as I was having problems as well. I’ve also been having problems with this “DNS pollution” going on with a lot of my different activities for sure. Definitely let me know if you need help with the additional issues!

Leave a Comment

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

Type here..

Exit mobile version