LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-19-2006, 05:49 PM   #1
robbbert
Member
 
Registered: Oct 2005
Location: Hannover, Germany
Distribution: Let there be Ubuntu... :o)
Posts: 573

Rep: Reputation: 32
Smile 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:
Quote:
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:
Quote:
robert@ubuntu:~$ sudo update-alternatives --config java
Password:
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!
robbbert
 
Old 03-20-2006, 06:45 AM   #2
Lenard
Senior Member
 
Registered: Dec 2005
Location: Indiana
Distribution: RHEL/CentOS/SL 5 i386 and x86_64 pata for IDE in use
Posts: 4,790

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

Code:
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/java.sh 
file, example below;

export JAVA_HOME="/usr/java/jre1.5.0_06/bin"
export JAVA_PATH="$JAVA_HOME"
export PATH="$PATH:$JAVA_HOME"

When done creating or editing the file type; 

source /etc/profile.d/java.sh

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

which java

and the results should read something like;

/usr/java/jre1.5.0_06/bin/java

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.
 
Old 03-20-2006, 08:15 AM   #3
raven4d
Member
 
Registered: Feb 2006
Location: Damascus-Syria
Posts: 117

Rep: Reputation: 15
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 .

 
Old 03-20-2006, 08:51 AM   #4
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 57
Quote:
Originally Posted by robbbert
Could you please point me to setup Sun Java?
Thanks indeed!
robbbert
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.


Håkan
 
Old 03-20-2006, 02:44 PM   #5
robbbert
Member
 
Registered: Oct 2005
Location: Hannover, Germany
Distribution: Let there be Ubuntu... :o)
Posts: 573

Original Poster
Rep: Reputation: 32
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!

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*
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set the default WM beajedi Linux - General 6 02-20-2004 02:17 PM
Java can't find package, but PATH set correctly (j2se1.4.0, java.util.regex package) Ethan Programming 5 02-06-2004 09:55 PM
how to replace default netscape with 6.1 version gogo Linux - General 9 11-24-2003 05:09 AM
Is there a way to set up the default look for all new users? HGeneAnthony Linux - General 1 03-17-2003 04:29 AM
How to set Default Java VM/SDK in SuSE? shassouneh Linux - Software 10 09-23-2002 05:19 PM


All times are GMT -5. The time now is 10:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration