Thursday 7 November 2013

Downgrading / Switching openJDK and other Java versions in Ubuntu

If you are running openJDK or other versions and need to develop or use Java in an older version there is an easy way to switch working versions.

First confirm your current version;

root# java -version 
java version "1.7.0_25" 
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2) 
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode) 

Note: This way assumes that you have upgraded but not removed the older version. If you only have the newer version then first install the older version you want to downgrade to then you can simply switch.

The command you should run is:

root# update-alternatives --config java 

Upon running you will receive a similar screen and switching to another version is as easy as typing a number.

There are 3 choices for the alternative java (providing /usr/bin/java). 

Selection Path Priority Status 
------------------------------------------------------------ 
* 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
 2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
 3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode

Press enter to keep the current choice[*], or type selection number: 1 
update-alternatives: using /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode 

You can then check your version again;

root# java -version 
java version "1.6.0_27" 
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.13.04.2) 
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

No comments:

Post a Comment