Saturday, November 10, 2007

Java on Ubuntu

Ubuntu has GCJ installed by default. A different version of Java can be installed using the Synaptic Package Manager. Sun's Java 1.5 and 1.6 are available through the package manager.

The problem is, even after installing Sun's Java, GCJ is the default.

The default version of java can be changed using the update-java-alternatives command.

update-java-alternatives -l will give the list of all installed java packages.
example output:
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-gcj 1042 /usr/lib/jvm/java-gcj

update-java-alternatives -s java-1.5.0-sun will set Sun's java as the default.

For some applications like Ant, Tomcat to run, you nee to set the JAVA_HOME environment variable like below
export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun

The above export can be put in /etc/bash.bashrc (for all users) or /home/<user>/.bashrc (for a particular user) so that JAVA_HOME is available on logon.

No comments: