Start a Minecraft server on Linux

My kids have a Minecraft server sitting in a closet somewhere. They connect to it from any machine in the house, but only when they’re at home. It isn’t opened to the outside world. The server has a Ryzen 7 5800H and 12GB of RAM, and runs very well when allowing Paper-MC to run with limitations. Paper-MC is “The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies.”

To get started on your new Minecraft adventure, install TLauncher (link). TLauncher is a third party Minecraft launcher that incorporates mods, skins, plugins, and multiple server instances. You’ll need to confirm server.properties has online-mode=false, or else TLauncher won’t connect to your shiny, new server. That’s because Microsoft performs an authentication check on launchers when connecting. This modification is already taken care of in the script below, but it’s good to know that it’s there.

One more incredibly frustrating thing, is that (Java) Minecraft on PC isn’t the same version that you run on your tablet, phone, or Chromebook. These will not connect to each other, and it’s not worth trying to get the workarounds going. Trust me. If you’re going to run this server, you’ll need to have only PCs connect to it. It sucks and is stupid, but that’s the way things are. We have a support group available at the local Y and meet on Tuesday evenings.

Note: You only need to run the below bash script once to get the server running. After the first time, run the newly created start.sh. Don’t forget to change server.properties for your style of gameplay. You can review the details of the file here.

setup_minecraft.sh

#!/bin/bash

# Check here for newest version: https://papermc.io/downloads/paper
PAPER_VERSION="1.21"
PAPER_BUILD="119"

# Update your system
sudo apt update && sudo apt upgrade -y

# Install dependencies
sudo apt install -y openjdk-17-jre-headless wget screen

mkdir -p ~/minecraft_server && cd ~/minecraft_server

# Download the latest PaperMC build
wget -O paper.jar https://api.papermc.io/v2/projects/paper/versions/$PAPER_VERSION/builds/$PAPER_BUILD/downloads/paper-$PAPER_VERSION-$PAPER_BUILD.jar

# Accept the EULA
echo "eula=true" > eula.txt

# Disable first-party launcher check
sed -i 's/online-mode=true/online-mode=false/' server.properties

# Create a startup script - high performance graphical settings included
cat << EOF > start.sh
#!/bin/bash
java -Xms512M -Xmx1024M -XX:+UseG1GC -XX:MaxGCPauseMillis=50 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50 -XX:+AlwaysPreTouch -jar paper-$PAPER_VERSION-$PAPER_BUILD.jar nogui
EOF
chmod +x start.sh

You’ll need to change the script permissions to allow for execution, then run it.

$ chmod +x setup_minecraft.sh
$ ./setup_minecraft.sh

When you’re looking to start the server, run the following. This will put the server in a screen session, where you could hit CTRL+A+D to detach from the screen and close the session without closing the server.

$ screen -S minecraft -d -m ./start.sh

Sources

 

  • 31July2024
    • Made the version number a variable so it can be updated in one spot.
Previous: Bing Next: Kasa Smart Plugs controlled with Python