Advertisement

Minecraft

Start Script & JVM Flags

Most Minecraft servers start with a one-line script copied from a forum years ago, and it is usually wrong in the same two ways: the heap takes every gigabyte the machine has, and the garbage collector runs on defaults. This writes the script for your server software and memory, with the flags PaperMC recommends.

All the memory the server has, not the heap. The heap is worked out from it below.

Suggested 6.5 GB — the rest is left for the JVM itself and the operating system. Giving the heap everything is the most common cause of a server being killed for running out of memory.

Whatever the file you downloaded is called. Renaming it to something short is fine.

Leave as java unless several Java versions are installed — then give the full path to the one this Minecraft version needs.

start.sh

#!/usr/bin/env bash
# Run from the server folder: chmod +x start.sh && ./start.sh
cd "$(dirname "$0")"

while true; do
  java -Xms6656M -Xmx6656M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar nogui
  echo "Server stopped. Restarting in 10 seconds - press Ctrl+C to cancel."
  sleep 10
done

start.bat

@echo off
cd /d "%~dp0"
:start
java -Xms6656M -Xmx6656M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar nogui
echo Server stopped. Restarting in 10 seconds - close this window to cancel.
timeout /t 10
goto start

Advertisement

How it works

You tell it how much memory the machine or container has; it leaves room for the JVM and the operating system and gives the rest to the heap, setting -Xms and -Xmx to the same value so the heap never has to grow mid-game. With Aikar's flags on, it adds the G1 collector settings PaperMC publishes, switching to their large-heap variant above 12 GB. Forge from 1.17 and NeoForge are handled differently because they do not start from a single jar: their installer writes run.sh and run.bat, and the JVM options belong in user_jvm_args.txt instead.

Advertisement

Common mistakes

The flags reduce lag spikes from garbage collection; they do not make a server faster in general, and they cannot make up for too little memory or a slow CPU. Check the Java version too: a start script pointing at the wrong Java fails with an unsupported class file version error before any of these flags matter.

Rather not run the server yourself?

These tools are free and funded by the two hosting services we run. If you want a server that is already set up, here they are.

Advertisement