Memory: -Xms and -Xmx
-Xmx is the most memory Java's heap may use and -Xms what it takes at the start. Setting both to the same number, as this script does, is what Aikar's flags expect: the server takes its memory once instead of growing and shrinking. Java needs roughly 1 to 2 GB more than -Xmx for itself, and the system needs room on top, so on a 16 GB machine 12 GB is about the most to give. A panel such as Pterodactyl counts that overhead against your plan too, so leave a gigabyte or two there.
How much is enough
The suggestion is a rule of thumb, not a measurement: 2 GB for a plugin server itself, 3 for Fabric and 4 for Forge or NeoForge, then about 1 GB more for every 10 players past the first 5 (8 on a modded server) and for every 25 plugins or 30 mods. Big modpacks often say what they need; use that if it is more. Past about 10 to 12 GB a plugin server rarely runs better, since the extra mostly makes each garbage collection pass longer.
Aikar's flags
Aikar's flags are Java garbage collector settings tuned for how a Minecraft server uses memory: many short-lived objects every tick. They keep pauses short so ticks do not stall. PaperMC recommends them for every server; over 12 GB a slightly different set is used, and the script picks it for you. They work on vanilla, Fabric and Forge servers too.
The Java each version needs
Minecraft 26.1 and later need Java 25; 1.20.5 to 1.21.11 need Java 21; 1.18 to 1.20.4 need Java 17; 1.17 needs 16; 1.16.5 and older were made for Java 8. A newer Java usually runs an older server, but an older Java cannot start a newer one. Checked against Java Edition 26.3.
Running it
Put the script in the server folder, next to the jar. On Windows, double-click start.bat. On Linux or macOS, run chmod +x start.sh once, then ./start.sh; on a remote machine, start it inside screen or tmux so it keeps running when you log out. With the restart loop, typing stop restarts the server after 10 seconds; press Ctrl+C during the wait to stop for good. The script is made in this page and saved straight from it; nothing is sent anywhere.
Questions
Why does my server say it needs to agree to the EULA?
Every server needs eula.txt to say eula=true. Run it once to make the file, then change false to true, or turn on Accept the EULA here, which writes the file each start.
Does more RAM stop lag?
Only if the server is running out. Lag is more often the processor, a high view-distance, too many entities or a plugin. Watch memory use with a tool like spark before adding more, and lower view-distance in server.properties first.
Why use Forge's run.sh at all?
Forge and NeoForge from Minecraft 1.17 are started through argument files their installer writes, not one jar. This script calls the same argument files, so you get your memory, flags and restart loop with no need to edit user_jvm_args.txt.
Will this work on Bedrock?
No. Bedrock Dedicated Server is a program of its own, not Java, and takes none of these settings.