Changing Java Versions in Ubuntu
Submitted by Chadarius on Wed, 2008-10-08 10:22.
I recently needed to bring up a java app that I hadn't used in quite some time. At least as long as before I had Kubntu 8.04 installed. Back then I was using Java 6 (1.6.x) as the default JRE on my latptop. Now however, the app was failing with all kinds of errors.
As with any OS that can use Java, just because you have a java version installed, doesn't mean that version is the one that is launched by default. I have Java-gcj, Java 5 and Java 6 all installed on my Kubuntu 8.04 laptop. Java-gcj was currently the default java version.
In Linux, the way the java default is setup is both elagent and confusing all at the same time (Linux in a nutshell if you ask me, and I love it!). In Linux the /usr/bin/java file is really just a link to the java version that you want to be the default. But /usr/bin/java links to another link to /etc/alternatives/java which in turn links to the actual java binary at /usr/lib/jvm/java-gcj/jre/bin/java.
I want it to point to the very latest Java version from Sun. the current version that I have from Sun is at /usr/lib/jvm/java-1.6.0.07-sun/jre/bin/java. But I do not want to link to that java binary. Why? Because Sun updates java versions quite frequently. If Sun updates Java due to a security issue and that gets updated in Kubuntu, I would have to go in and change the link all over again. So instead, when Java gets installed for a particular version the package installs a handy link for a particular java family version. In this way I can ensure that I always use a Java 6 binary, but Kubuntu can update the minor versions within the Java 6 family without me having to be constantly updating links to the right binary file.
Confused yet? Let's take a look at it in a different way.
/usr/bin/java -> /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
and /usr/lib/jvm/java-6-sun -> /usr/lib/jvm/java-1.6.0.07-sun
So /usr/bin/java really points to /usr/lib/jvm/java-1.6.0.07-sun/jre/bin/java. But that a ride to get there!
In order to change the version I ran the following:
cd /etc/alternatives
sudo ln -s /usr/lib/jvm/java-6-sun/jre/bin/java
My java program requiring Sun Java 6 now works perfectly.
»
- Chadarius's blog
- Login to post comments
- 2323 reads


