I only recently discovered the different JVM's on the wiki page and thought I'd start tinkering. Its been difficult to find documentation on how to configure Java on Ubuntu though.

Lets say I wanted to change the JRE or JDK that I'm using, I could crack open a terminal and say

sudo update-alternatives --config java

And then pick from one of the installed versions.

If I'm understanding JVM's right (which I may very well be not), You can configure the openJDK to use alternative JVM's (Eg JAMVM) and run it as such

jamvm -jar foo.jar

2 questions,

1: Do i have the concept of a JVM right? As in, is this possible?

2: If so how do i configure the JVM and switch the default to a JVM of my choosing?

  • Great, add a good answer to your question (you can answer them yourself) and get some up votes! – Bruno Pereira Feb 24 '12 at 13:38
  • @BrunoPereira Done! Hopefully that covers the bunch. – OVERTONE Feb 25 '12 at 16:27

Feel free to use this as a reference to tinkering with Java at runtime.

Choosing your JRE

To choose your JRE, use

sudo update-alternatives --config java

This will give something like the following output.

  Selection    Path                                            Priority   Status
  0            /usr/lib/jvm/java-6-openjdk/jre/bin/java         1061      auto mode
* 1            /usr/lib/jvm/java-6-openjdk/jre/bin/java         1061      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java             63        manual mode
  3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode

You can then select which Java runtime you want through the number selection.

Choosing your JVM

Sun/Oracle have two JVM choices, -server and -client. If you select the OpenJDK as your Java runtime environment you have additional options.

When you type java into the terminal with no other parameters, the help lists several optional VMs. I'm not sure which ones come with OpenJDK but 3 popular ones are JamVM, Zero and Cacao

To use these, simply type

java -jamvm 'your other parameters here'
java -cacao 'your other parameters here'
java -zero 'your other parameters here'
java -server 'your other parameters here

The -server VM is normally the default. You can also specify -client but in 64-bit IcedTea6 it appears to run the same version as -server. There are most likely others but I find the default option to be the most responsive.

Setting your Memory

Finally, how to set the memory of Java (just because)

java -Xmx1024m -Xms128m 'your other parameters here'

This limits the memory allowed for the Java program to a maximum of 1024 MB, and sets its initial memory size to 128 MB. This is a great way of defining minimum system requirements. The Java 6 man page for the java command describes these options and others.

That's all. If anyone has additional Java tweaks for Ubuntu then leave them in the comments and I'll add them.

| improve this answer | |
  • There are about 47 executable files in $JAVA_HOME/bin and $JAVA_HOME/jre/bin which cries for an script to update all the entries in the alternatives system. See the /usr/lib/jvm/.java*.jinfo files. – user unknown Jun 5 '12 at 23:21
  • How do I set the default JVM? From what I've heard, -server has long start-up times, so why isn't -client the default anyway for a user installation? – dhardy Feb 18 '13 at 6:58
  • Is there a way to actually change the defaults, or do you have to explicitly set the JVM and memory limits each time (or in each individual startup script)? – aij Apr 2 '14 at 2:33

To set the default JVM inside an OpenJDK installation you need to edit the jvm.cfg configuration file located inside the /usr/lib/jvm/java-version-openjdk-arch/jre/lib/arch/jvm.cfg

Ubuntu expose the jvm.cfg file inside the /etc/ directory depending on OpenJDK version. /etc/java-6-openjdk/jvm-arch.cfg or /etc/java-7-openjdk/jvm-arch.cfg

The top most -jvmname KNOWN line inside the jvm.cfg file determine the default JVM.

There is no configuration tool available thus you have to locate and edit these files manually.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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