On Windows, I could change how much RAM Java could use by typing something like -Xincgc -Xmx2048M in the Java Runtime Parameters. How can I do that in Ubuntu?
2 Answers
The same applies on Linux. If you want to make the options permanent, you can export the JAVA_OPTS
environment variable.
I recommend to do it on a per-user basis. Modify the .profile
file in your home directory (or .bash_profile
if it exists and you use bash) to include this line:
export JAVA_OPTS='-Xincgc -Xmx2048M'
After setting this, you need to restart shell sessions for it to apply.
Alternatively, you can also modify the system-wide profile in /etc/profile.
Edit: Settings for the Java Browser Plugin are defined in the Java Control Panel: http://docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/control_panel.html.
-
How does the same apply to Linux? I can't go to Control Panel, open Java and change the settings. What do I do?– AndriFeb 25, 2012 at 16:49
-
1If I'm not wrong, that control pannel applies only to the Java Plugin for the Browser. If that is what you look for,it is located at /jre/bin/ControlPanel (docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/…)– jjmontesFeb 25, 2012 at 17:05
-
That's not what I meant. All I need to know is how I could make Java be able to use more RAM than it does now.– AndriFeb 25, 2012 at 17:14
If I am not mistaken they are the same in Linux. With the Java command you have the 2 options:
- Xmx sets the maximum memory heap size.
- Xms sets the minimum memory heap size.
So doing -Xmx1024m -Xms128m
should work.
Here is an extract from doing a man java
in the terminal
-Xmsn
Specify the initial size, in bytes, of the memory allocation
pool. This value must be a multiple of 1024 greater than 1MB.
Append the letter k or K to indicate kilobytes, or m or M to
indicate megabytes. The default value is chosen at runtime
based on system configuration. For more information, see
HotSpot Ergonomics
Examples:
-Xms6291456
-Xms6144k
-Xms6m
-Xmxn
Specify the maximum size, in bytes, of the memory allocation
pool. This value must a multiple of 1024 greater than 2MB.
Append the letter k or K to indicate kilobytes, or m or M to
indicate megabytes. The default value is chosen at runtime
based on system configuration. For more information, see
HotSpot Ergonomics
Examples:
-Xmx83886080
-Xmx81920k
-Xmx80m
So that basically sums it up about doubts using the same parameters.
To use this go to a terminal and type it with a jar program. In my example I am using the minecraft server: java -Xms1024M -Xmx2048M -jar minecraft.jar
.
Here is an image of what happens:
I should note that the parameters are Case Sensitive. So xmx1024M is not the same as Xmx1024M.
-
Well, I didn't ask what parameters I should use. I asked where I should type the parameters. If I type -Xmx1204m -Xms128m, it says unknown command.– AndriFeb 25, 2012 at 16:32
-
From your question it seemed you already knew where to type them since you were using them already. Sorry. I updated the answer to include an image of the output of the command and the complete command line for java and parameters. This is all typed from the terminal. Feb 25, 2012 at 17:51