study071126@minecraft:~$ cd ~/minecraft/ && sh ./run.sh nogui
Error occurred during initialization of VM
Too small maximum heap
study071126@minecraft:~/minecraft$ ls
config forge-1.20.1-47.2.0-installer.jar logs run.sh
defaultconfigs forge-1.20.1-47.2.0-installer.jar.log mods user_jvm_args.txt
eula.txt libraries run.bat
study071126@minecraft:~/minecraft$ java -Xms10G -Xmx14G -jar ^C
study071126@minecraft:~/minecraft$ java -Xms10G -Xmx14G -jar forge-1.20.1-47.2.0-installer.jar --nogui
JVM info: Private Build - 18.0.2-ea - 18.0.2-ea+9-Ubuntu-222.04
java.net.preferIPv4Stack=true
Current Time: 07/02/2024 01:44:54
Exception in thread "main"
joptsimple.UnrecognizedOptionException: nogui is not a recognized option
at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
at joptsimple.OptionParser.parse(OptionParser.java:396)
at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:93)
study071126@minecraft:~/minecraft$ ^C
study071126@minecraft:~/minecraft$ cd ~/minecraft/ && sh ./run.sh nogui
Error occurred during initialization of VM
Too small maximum heap
study071126@minecraft:~/minecraft$ ^C
study071126@minecraft:~/minecraft$ ^C
study071126@minecraft:~/minecraft$ sudo java -Xmx9218m -Xms2048m -jar forge-1.20.1-47.2.0-installer.jar --noguiJVM info: Private Build - 18.0.2-ea - 18.0.2-ea+9-Ubuntu-222.04
java.net.preferIPv4Stack=true
Current Time: 07/02/2024 01:47:35
Exception in thread "main"
joptsimple.UnrecognizedOptionException: nogui is not a recognized option
at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
at joptsimple.OptionParser.parse(OptionParser.java:396)
at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:93)
study071126@minecraft:~/minecraft$ ^C
study071126@minecraft:~/minecraft$ cd ~/minecraft/ && sh ./run.sh nogui
Error occurred during initialization of VM
Too small maximum heap
study071126@minecraft:~/minecraft$ cd ~/minecraft/ && sh ./run.sh nogui
Error occurred during initialization of VM
Too small maximum heap
study071126@minecraft:~/minecraft$ sudo java -Xmx2048m -Xms9218m -jar forge-1.20.1-47.2.0-installer.jar --noguiError occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size
study071126@minecraft:~/minecraft$ sudo java -Xmx2048m -Xms9218m -jar forge-1.20.1-47.2.0-installer.jar --noguiError occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size
study071126@minecraft:~/minecraft$ sudo java -Xmx2048m -Xms2048m -jar -jar forge-1.20.1-47.2.0-installer.jar --nogui
JVM info: Private Build - 18.0.2-ea - 18.0.2-ea+9-Ubuntu-222.04
java.net.preferIPv4Stack=true
Current Time: 07/02/2024 01:48:42
Exception in thread "main"
joptsimple.UnrecognizedOptionException: nogui is not a recognized option
at joptsimple.OptionException.unrecognizedOption(OptionException.java:108)
at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510)
at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56)
at joptsimple.OptionParser.parse(OptionParser.java:396)
at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:93)
study071126@minecraft:~/minecraft$ cd ~/minecraft/ && sh ./run.sh nogui Error occurred during initialization of VM
study071126@minecraft:~/minecraft$ ^C
study071126@minecraft:~/minecraft$ sh ./run.sh
Error occurred during initialization of VM
Too small maximum heap
study071126@minecraft:~/minecraft$
2 Answers
Because you're not doing it properly.
If you want a more specific answer, properly define "it" and "work".
More specifically (albeit speculatively), it appears that you are attempting to start a modded Minecraft server. Consult the mod's installation and startup directions. Also consult the error messages of which you are in receipt. Inspect the script you are using to ensure it is running the commands specified in the project documentation.
Some of the output you are getting and what it appears to mean -- again subject to the specifications of the application with which you are having problems:
Error occurred during initialization of VM
Too small maximum heap
The application you are starting is requesting more memory allocation than the JVM in which it was invoked was permitted.
Exception in thread "main"
joptsimple.UnrecognizedOptionException: nogui is not a recognized option
You provided a runtime option (nogui) which the application does not recognize. Consult the application's documentation.
As a (further) aside: If anyone is telling you to run a game server with a command starting with sudo, stop heeding any directions from that person as they are poor, probably incorrect, and fraught with all sorts of peril.
Note that forge-1.20.1-47.2.0-installer.jar is not the actual Minecraft server, but the installer for it. It appears you've already executed it once, and there is no need to run it again.
Note that there is a file named user_jvm_args.txt. It is a text file. If you view it (e.g. with less ~/minecraft/user_jvm_args.txt), you'll see something like this:
# Xmx and Xms set the maximum and minimum RAM usage, respectively.
# They can take any number, followed by an M or a G.
# M means Megabyte, G means Gigabyte.
# For example, to set the maximum to 3GB: -Xmx3G
# To set the minimum to 2.5GB: -Xms2500M
# A good default for a modded server is 4GB.
# Uncomment the next line to set it.
# -Xmx4G
This is where you could add the Java memory parameters. You could remove the # sign from the last line and add your options there, or just add a new line at the end with your memory options:
echo "-Xms10G -Xmx14G" >> ~/minecraft/user_jvm_args.txt
(This command line should be run only once: if you want to change the options afterwards, you should use a regular text editor to avoid adding more and more lines to the file.)
After this, the cd ~/minecraft/ && sh ./run.sh nogui should work.
The run.sh is a shell script, so it is also a text file. Generally, when a program comes with a script intended to be used to start it, it suggests the script is the expected place for any parameters and other customizations, so reading the script before running it is a good idea. less ~/minecraft/run.sh would be one way to view its contents.
In this case, you'll see something like this:
#!/usr/bin/env sh
# Forge requires a configured set of both JVM and program arguments.
# Add custom JVM arguments to the user_jvm_args.txt
# Add custom program arguments {such as nogui} to this file in the next line before the "$@" or
# pass them to this script directly
java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.20.2-48.1.0/unix_args.txt "$@"
If you want to always run the server with the nogui parameter, this tells you what to do. Just add the nogui to the last line, so it becomes:
java @user_jvm_args.txt @libraries/net/minecraftforge/forge/1.20.2-48.1.0/unix_args.txt nogui "$@"
After that, cd ~/minecraft/ && sh ./run.sh would be enough to start the server in the nogui mode.
And like DopeGhoti said in their answer, you should never run a game server with sudo. Game servers have so much complexity that they are almost certain to contain some not-yet-widely-known vulnerability, and if you run one with root permissions, anyone that exploits such a vulnerability will immediately have total control of your system.
While getting hacked as a regular user is bad enough (these days, it usually means your cloud server will be used to mine bitcoins for the intruder, with you paying the bill), allowing the intruder an easy way to get root access is worse: the only sure way to recover from that is to delete the cloud server and create a new one.
(I used absolute paths and extraneous cd commands on purpose in this answer; I'm assuming the asker is a newbie whose command line skills and even the concepts of separate shell sessions and directory tree traversal may be still a bit uncertain.)
-Xms10G -Xmx14Gand-Xmx9218m -Xms2048mwhich look like the options are missing equal signs. Perhaps directions were not followed exactly.