Saturday, October 24, 2009

Set java version in Linux

Java is a great cross-platform programming language that produces code that will work across operating systems and hardware architectures, provided the other computer also has Java installed. There are, however, some different versions of Java out there and not all software always plays nicely with each different version. Right now the main releases of Java that are in use are Java 5 (aka 1.5) and Java 6 (aka 1.6). To see which version of Java you are running, use this command:
$ java -version
To see all of the version of Java you have installed that you could be using, use this command:
$ update-java-alternatives -l
This will list each version of Java you can use. On one of my systems, for example, when I run that command I get this output:
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun
Here I have three version of Java installed: Sun's version of Java 5 (aka 1.5), version 6 of the OpenJDK, and Sun's version of Java 6. If I wanted to switch to using Sun's version Java 6, I would enter this command:
$ sudo update-java-alternatives -s java-6-sun
To switch version, you enter the name of the Java version you want to use after the -s flag. For more information check out the man page with this command:
$ man update-java-alternatives

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.