Tools
Server start script generator
Set the memory and the server jar — get start.sh for Linux and macOS or start.bat for Windows with Aikar's flags, as PaperMC recommends. The Velocity proxy gets its own flag set.
Start script
This is the Java heap (Xms and Xmx). Leave memory for the system too: Java itself uses some beyond the heap.
Your start.sh
#!/usr/bin/env sh
while [ true ]; do
java -Xms4096M -Xmx4096M -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 server.jar --nogui
echo Server restarting...
echo Press CTRL + C to stop.
done
Paper 26.x requires Java 25; 1.20–1.21.11 run on Java 21.
Running your server with this script
Save the file in the server folder next to the server jar. On Linux make it executable — chmod +x start.sh — and run ./start.sh; on Windows just double-click start.bat.
Aikar's flags tune the G1 garbage collector for Minecraft: short pauses instead of rare long ones that players see as lag. The set is the same as in PaperMC's start script generator; for the Velocity proxy PaperMC gives a shorter one.
Xms equals Xmx: Java takes all the memory at once and doesn't spend time growing the heap. How much to give depends on your player count, plugins and world — see the article on memory. To keep a server running on Linux, systemd is better: it starts the server again after the machine reboots.
You can check the load with the spark profiler. DGuard takes 0.03 % of one core on the main thread — its checks run in network threads and don't eat into the tick.
Read in the knowledge base
FAQ
What are Aikar's flags?
A set of Java options for the G1 garbage collector tuned for Minecraft. PaperMC recommends them for Paper servers and builds them into its start script generator.
Do Aikar's flags suit Velocity?
PaperMC gives the proxy a separate set — pick "Velocity". A proxy needs little memory and no --nogui.
How much memory should I set?
As much as the server needs, but not all of the machine's memory: the system and Java itself need headroom. The full calculation is in "How much RAM does a server need".
Why --nogui?
Without it the server opens a graphical window. On a machine without a screen or at a host it's useless and only costs resources.
The tools are free. So is anti-cheat protection
DGuard — the best anticheat for a modern Minecraft server — catches all 47 cheat types in our comparison; the nearest rival, Intave, catches 27. Free up to 30 players online, with the same protection as on paid plans.