Easy way to set your Java enviroment in Ubuntu

Did you know, that there is a really simple way to set your Java environment in Ubuntu, when you have multiple Java packages installed?

Everything you need is to run update-java-alternatives command with correct parameters.

Just look at your installed Java packages (use ls -l /usr/lib/jvm/ command):

petr@pchytil-ws:~/nbsrc_main/main/mercurial$ ls -a1 /usr/lib/jvm/ 
.
..
java-1.5.0-gcj-4.2-1.5.0.0
java-1.5.0-sun
java-1.5.0-sun-1.5.0.15
.java-1.5.0-sun.jinfo
java-6-sun
java-6-sun-1.6.0.06
.java-6-sun.jinfo
java-gcj
.java-gcj.jinfo

You can see three .jinfo files here. Just take name of this files without extension and you have right parameters for update-java-alternatives command.

On my machine, I have three Java packages installed:

java-1.5.0-sun
java-6-sun
java-gcj

So choose the package you want and run

sudo update-java-alternatives -s <java_name> 

for example i want to use JDK 6.0:

sudo update-java-alternatives -s java-6-sun

This command creates links for all important Java binaries. java -version command should now give you the Java version, which you always dreamed of ;-).

petr@pchytil-ws:~$ java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)

Comments:

Maybe a little bit off... but..

I'm really busting my head on how to install Java 6 update 11 on Ubuntu. Synaptic package manager only updates to 07. Why is this anyways?

Thanks!

Posted by Jeff on December 07, 2008 at 05:54 PM CET #

Well, that is because the Ubuntu repositories are updated with some delay since their primary concern is to have highly stable repositories not necessary the latest versions. I suppose that in time, as Java will become more interesting to the linux community the jump to newer versions will happen faster.

Posted by Mricea on December 09, 2008 at 02:01 AM CET #

That's true I'm afraid. Repositories are often a bit delayed when it comes to JDKs.

Anyway, you can always install JDK manually using installers on http://java.sun.com/javase/downloads/index.jsp and then update links and system properties manually. Luckily, you don't have to do much setting when you only want to run NetBeans with this JDK. In this case install JDK somewhere and then change <nbinstalldir>/etc/netbeans.conf file or start NetBeans from command line with appropriate parameter: ./netbeans --jdkhome <jdkinstalldir>.

Posted by Petr Chytil on December 09, 2008 at 03:25 PM CET #

petr chytil: hey do you think you could give me a detailed method to update links and system properties after installing java update 11 manually from sun's website? like the threadstarter, i've been busting my head trying to install update 11 which it does fine (that's the easy part) i just can't get firefox to recognize it. and the system won't recognize it either... when i type java -version it still gives me update 7 as the one running. thnaks for any help you can give.

Posted by jin on December 18, 2008 at 02:13 PM CET #

I will just point out that if you type:

update-java-alternatives -l

... you will get a list of java alternatives that can be set up using "update-java-alternatives -s $ALTERNATIVE" command...

Thank you for this post, very helpful if you mess up with your Java environment...

Posted by joshis on January 06, 2009 at 06:13 AM CET #

Thank you!

Posted by Ari on September 15, 2010 at 10:30 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Petr Chytil

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today