Search This Blog

Tuesday, April 14, 2009

Changing / Selecting Java Versions in Ubuntu / XUbuntu

Okay, so I had Java6 installed by default when I installed XUbuntu. Now at work we primarily still use Java5 due to the backwards comparability etc etc, and so I needed to run that as my default JVM. Not a problem I thought.

(BTW: If I dont make it to the end of this article/post its the hiccups man!!!!I've got a mo*&&*ther f&*^king case of hiccups that just wont freaking go away. they been holding on to me for the last freaking hour and Im stuck as a fuck tryign to get rid of them. My chest is starting to hurt and I juast cant make them stop. Every freakin 10 seconds I hiccup!!! SHIIIIIIT!!!!....anyways bacak to Java Versions ey...although if this post stops half way through then you've been warne and all i could manage to do was to despreately push the publich button).

So I used Synaptic Package Manager and I happily installed Java 5. Then I went ahead and I type:

mkopka@random:~/Sandbox$ java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)


Ok, well thats no good. I want my Java 5 that I just installed. So what to do. A bit of research led me to a couple of things. First of all:

mkopka@random:~/Sandbox$ which java
/usr/bin/java
mkopka@random:~/Sandbox$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2009-04-02 13:42 /usr/bin/java -> /etc/alternatives/java
mkopka@random:~/Sandbox$ ls -la /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2009-04-11 18:04 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
mkopka@random:~/Sandbox$ ls -la /usr/lib/jvm/java-6-sun/bin/java
lrwxrwxrwx 1 root root 15 2009-04-02 13:39 /usr/lib/jvm/java-6-sun/bin/java -> ../jre/bin/java


Okay, so that led me through a bunch of soft links from /usr/bin to /etc/alternatives to /usr/lib/jvm/java-6 and then back up a directory to the jre/bin. Interesting. Whats more insteresting was this:

mkopka@random:~/Sandbox$ ls -l /usr/lib/jvm/
total 8
lrwxrwxrwx 1 root root 23 2009-04-11 18:03 java-1.5.0-sun -> java-1.5.0-sun-1.5.0.16
drwxr-xr-x 10 root root 4096 2009-04-11 18:04 java-1.5.0-sun-1.5.0.16
lrwxrwxrwx 1 root root 19 2009-04-02 13:39 java-6-sun -> java-6-sun-1.6.0.10
drwxr-xr-x 8 root root 4096 2009-04-11 18:04 java-6-sun-1.6.0.10



So it seems like we got sim links galore occurring. Which made me think, this is gonna be a total shit trying to re-simlink all of that mess.Surely theres got to be another way.......and guess what? There is!!! Thank god almighty for XUbuntu!!!

Okay so this is what I did:

mkopka@random:~/Sandbox$ sudo update-alternatives --config java
[sudo] password for mkopka:

There are 2 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
*+ 1 /usr/lib/jvm/java-6-sun/jre/bin/java
2 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java

Press enter to keep the default[*], or type selection number: 2
Using '/usr/lib/jvm/java-1.5.0-sun/jre/bin/java' to provide 'java'.
mkopka@random:~/Sandbox$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) Server VM (build 1.5.0_16-b02, mixed mode)



The line above in bold is all i needed to be provideed with a nice menu for configuring my default java versioon. And then a quick java -version and looky looky we now are running java 5 as the default. Damn it I luuurve linux/XUbunutu more and more the more I use it!.

So then to switch the javva version and the javac version that is being used these are used:

sudo update-alternatives --config java ---> is used to choose the java version
sudo update-alternatives --config javac --> is used to change the javac version

No comments:

Post a Comment