-   Linux - Software (
-   -   How to set the default Java version (

robbbert 03-19-2006 06:49 PM

How to set the default Java version
Hi all, excuse me to ask a newbie question but I've checked several FAQs and can't seem to find it out.

This is a Ubuntu Linux distribution, and I've installed NetBeans IDE, being bundled with Sun JDK 5.0.

I'd like to set Sun JRE 5.0 as "default" for all applications that call "java".

Currently, checking the Java version is resulting in:

robert@ubuntu:~$ java --version
java version "1.4.2"
gij (GNU libgcj) version 4.1.0 (Ubuntu 4.1.0-1ubuntu4)
Sun Java isn't in the list:

robert@ubuntu:~$ sudo update-alternatives --config java
There are 3 alternatives which provide `java'.
Selection Alternative
*+ 1 /usr/lib/jvm/java-gcj/bin/java
2 /usr/bin/gij-wrapper-4.1
3 /etc/alternatives/kaffe-system/bin/java
Press enter to keep the default[*], or type selection number:
Could you please point me to setup Sun Java?
Thanks indeed!

Lenard 03-20-2006 07:45 AM

This may help (it was written for Red Hat distros, but should provide you with the steps);


Reconfiguring the default Java configuration

This is done as root or equivalent.

First remove /var/lib/alternatives/java file by typing;

rm /var/lib/alternatives/java

When asked press the 'y' key,

Now to create the new (corrected) alternatives file for java type
the following commands as root (modify for jdk as needed);

/usr/sbin/alternatives --install /usr/bin/java java /usr/lib/jvm/jre-1.4.2-gcj/bin/java 1

/usr/sbin/alternatives --install /usr/bin/java java /usr/java/j2re1.5.0_06/bin/java 2

/usr/sbin/alternatives --config java

You should now see for example:

There are 2 programs which provide 'java'.

  Selection    Command
  1          /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2          /usr/java/j2re1.5.0_06/bin/java

Enter to keep the current selection[+], or type selection number:

Type: <choose 1 or 2>

In the example above java is already configured correctly [*+ 2] to
use Sun's Java, no changes are needed, just press the Enter key here.
If you have been following the instructions then you should have
the same results (version numbers may be sightly different).

Now type; /usr/sbin/alternatives --display java

You should see for example;

java - status is manual.
 link currently points to /usr/java/j2re1.5.0_06/bin/java
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1
/usr/java/j2re1.5.0_06/bin/java - priority 2
Current `best' version is /usr/java/j2re1.5.0_06/bin/java.

Next you might want to create (or edit) /etc/profile.d/
file, example below;

export JAVA_HOME="/usr/java/jre1.5.0_06/bin"

When done creating or editing the file type;

source /etc/profile.d/

Now any user root or other wise should be able to use the command;

which java

and the results should read something like;


Also any user root or other wize should be able to use the command;

java -version

and the results should read something like;

java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

That's it, all done.

raven4d 03-20-2006 09:15 AM

thanx boss ..

i was looking for this a time ago !! the only benefit that i have from downloading the new jre was only the browser plugin !!!

now i can fully use my java .


hw-tph 03-20-2006 09:51 AM


Originally Posted by robbbert
Could you please point me to setup Sun Java?
Thanks indeed!

Sun's java isn't in the list because you didn't install it as a .deb package. Refer to the Ubuntu docs here on how to do it properly.


robbbert 03-20-2006 03:44 PM

Thank you Håkan, that worked almost out-of-the-box (not only for the JRE but for the JDK, too).

There was a slight problem, "sudo fakeroot" didn't work; the error message was something like "Java setups being executed as root tend to somtimes mess up common settings". Setting up Java as an unpriviledged user on the other hand resulted in some minor problems, basically in not replacing some shared logos/images and (slightly more problematic) WebStart not being installed.

Anyways, Sun Java is up and running! :p

Thanks Lenard too, I could figure that would work too, and I'll remember it when stepping into other Linux distris lateron. (CentOS BTW is one of my other favorites too.)

- Whew I'm a Linux geek *rofl*

All times are GMT -5. The time now is 04:26 PM.