Many programs use the JAVA_HOME environment variable in Linux. Here’s how to ’set’ it permanently. Note that the paths mentioned are accurate for uBuntu 10.04, and mileage may vary with other Linux flavours.

The path to use for JAVA_HOME is ‘/usr/lib/jvm/java-6-sun‘. Check that the path exists before continuing.

Add the following line to /etc/environment. Remember to sudo to launch your text editor, as this is a privileged file.
JAVA_HOME=”/usr/lib/jvm/java-6-sun”

You’re done! If you are using a desktop environment, log out and log in again to get it to stick.

If you are connected over ssh or running on the console of the server version, run this command to get your changes to stick:
source /etc/environment