Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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:

enter image description here

I should note that the parameters are Case Sensitive. So xmx1024M is not the same as Xmx1024M.

share|improve this answer
    
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. –  Andri Feb 25 '12 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. –  Luis Alvarado Feb 25 '12 at 17:51
    
Thanks a lot! :) –  Andri Feb 25 '12 at 18:17
    
If it helps remember to accept the answer. –  Luis Alvarado Feb 25 '12 at 18:19

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. If you use bash, modify your .bash_profile:

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.

share|improve this answer
    
How does the same apply to Linux? I can't go to Control Panel, open Java and change the settings. What do I do? –  Andri Feb 25 '12 at 16:49
    
If 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/…) –  jjmontes Feb 25 '12 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. –  Andri Feb 25 '12 at 17:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.