Startup Script
Generate a start.sh or start.bat for Paper, Purpur, Fabric, Forge, NeoForge or Velocity with Aikar's JVM flags, correct memory settings and an auto-restart loop.
Server
Full path if you have several Java versions installed.
start.sh
Save next to the server jar, run chmod +x start.sh, then ./start.sh (inside screen or tmux).
#!/usr/bin/env bash
cd "$(dirname "$0")"
while true; do
java \
-Xms6144M \
-Xmx6144M \
-XX:+AlwaysPreTouch \
-XX:+DisableExplicitGC \
-XX:+ParallelRefProcEnabled \
-XX:+PerfDisableSharedMem \
-XX:+UnlockExperimentalVMOptions \
-XX:+UseG1GC \
-XX:G1HeapRegionSize=8M \
-XX:G1HeapWastePercent=5 \
-XX:G1MaxNewSizePercent=40 \
-XX:G1MixedGCCountTarget=4 \
-XX:G1MixedGCLiveThresholdPercent=90 \
-XX:G1NewSizePercent=30 \
-XX:G1RSetUpdatingPauseTimePercent=5 \
-XX:G1ReservePercent=20 \
-XX:InitiatingHeapOccupancyPercent=15 \
-XX:MaxGCPauseMillis=200 \
-XX:MaxTenuringThreshold=1 \
-XX:SurvivorRatio=32 \
-Dusing.aikars.flags=https://mcflags.emc.gs \
-Daikars.new.flags=true \
-jar \
paper.jar \
--nogui
echo "Server stopped. Restarting in 5 seconds - press Ctrl+C to stop."
sleep 5
done
One-line command
java -Xms6144M -Xmx6144M -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+ParallelRefProcEnabled -XX:+PerfDisableSharedMem -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1HeapRegionSize=8M -XX:G1HeapWastePercent=5 -XX:G1MaxNewSizePercent=40 -XX:G1MixedGCCountTarget=4 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1NewSizePercent=30 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:G1ReservePercent=20 -XX:InitiatingHeapOccupancyPercent=15 -XX:MaxGCPauseMillis=200 -XX:MaxTenuringThreshold=1 -XX:SurvivorRatio=32 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar --nogui
For panels like Pterodactyl, use the flags in the startup field and set the memory limit about 1 GB higher than the heap. Check which Java your version needs in the Version Reference.
Guide
How to use
- 1Pick your server software and how much memory the server should use.
- 2Keep Aikar’s flags for game servers; proxies get Velocity’s recommended flags automatically.
- 3Download the script into the server folder and start it. On Linux, run it inside screen or tmux so it keeps running after you log out.
Good to know
Why -Xms equals -Xmx
Aikar’s flags pre-allocate the whole heap (-XX:+AlwaysPreTouch), so the server never pauses to grow memory. Leave 1–2 GB of the machine’s RAM for the operating system.
Above 12 GB
With more than 12 GB the generator switches to Aikar’s large-heap values (16M regions, larger young generation), as recommended by PaperMC.
Forge and NeoForge
Modern Forge and NeoForge start through the run.sh / run.bat their installer creates. Put the flags in user_jvm_args.txt instead of editing those scripts.
Questions
What are Aikar’s flags?
A set of G1 garbage collector settings tuned by Aikar for Minecraft servers. They shorten lag spikes caused by garbage collection and are the recommendation in the PaperMC documentation.
How much RAM does my Minecraft server need?
Small vanilla or Paper servers run well on 4–6 GB. Plugins, view distance and player count raise that; heavy modpacks often need 8–12 GB. Giving far more than needed can make garbage collection pauses longer.
Do these flags work with Java 21 and 25?
Yes. They use the G1 collector, which is the default in all current Java versions.