Monday, November 16, 2009

Changing default java setting on ubuntu

By default ubuntu comes with default GCJ flavor of Java which sometimes gives trouble when working in console to compile and run java programs. I recently faced to this problem. So here I thought to write how to change the default java setting on ubuntu.

Nothing much. we only need to change two things in advance that is java and javac command.

To choose Java
Just installing new Java flavours does not change the default Java pointed to by /usr/bin/java. You must explicitly set this:

$ sudo update-java-alternatives -l to see the current configuration and possibilities.

$sudo update-java-alternatives -s XXXX to set the XXX java version as default. For Sun Java 6 this would be sudo update-java-alternatives -s java-6-sun

Run java -version to ensure that the correct version is being called.

Alternative way

$sudo update-alternatives --config java

Although the above changes are done the system may still refer to old 'javac' setting.

To choose javac

To check which javac is fired when type javac -version use

$which javac

/usr/bin/javac

To check this javac is a real program or a symlink
$
ls -al /usr/bin/javac
lrwxrwxrwx 1 root root 23 2009-07-29 19:42 /usr/bin/javac -> /etc/alternatives/javac

It is a symlink. follow the same command again.
$ls -al
/etc/alternatives/javac

lrwxrwxrwx 1 root root 42 2009-11-16 14:59 /etc/alternatives/javac -> /usr/lib/jvm/java-gcj/bin/javac

So probably the /etc/alternatives/javac link will point to the not desired javac. Change it (as root) using:

$ln -sf /etc/alternatives/javac

No comments:

Post a Comment