Guides / Startup flags

How to make a start.sh for a Minecraft server on Linux

Create a Linux start.sh for your Minecraft server, make it executable, and keep it running after you log out.

Updated

On Linux, a start.sh script starts your server with the right memory and flags every time.

Make the script

In your server folder:

nano start.sh

Paste your script. A basic one:

#!/bin/sh
java -Xms4G -Xmx4G -jar paper.jar nogui

For a tuned version with Aikar's flags, use the startup flags generator and pick Linux. Save with Ctrl+O, then exit with Ctrl+X.

Make it executable

chmod +x start.sh
./start.sh

Keep it running after you log out

If you close SSH, the server stops with it. Run it inside screen or tmux:

screen -S minecraft
./start.sh

Press Ctrl+A then D to detach. Reattach later with screen -r minecraft.

Restart automatically

To restart after a crash, loop the command:

#!/bin/sh
while true; do
  java -Xms4G -Xmx4G -jar paper.jar nogui
  echo "Restarting in 5 seconds. Press Ctrl+C to stop."
  sleep 5
done

For a server that starts when the machine boots, a systemd service is the cleaner option.

Don't run it as root

Make a separate user for the server, such as minecraft, so a compromised plugin can't take over the whole machine.

Forge and NeoForge

Modern Forge and NeoForge include their own run.sh. Put your flags in user_jvm_args.txt instead of writing your own start script.

Work it out for your server

The free Startup flags generator gives you the exact settings for your setup.

Open the Startup flags generator →