Switch java version on CentOS 6

Olivier Grégoire picture Olivier Grégoire · Mar 13, 2014 · Viewed 23.6k times · Source

I have a CentOS 6 virtual box with Java 1.7 present.

$ java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
$ javac -version
javac 1.7.0_51

I need to use Java 1.6 instead of Java 1.7 so I installed it.

$ sudo yum install java-1.6.0-openjdk.x86_64
$ sudo yum install java-1.6.0-openjdk-devel.x86_64

When I check the version again, I get the same as previously. For other projects I will need Java 1.7 so I want to keep it.

Now I would like to configure my virtual machine so that both the default JDK and the default JRE are 1.6. How do I do that? Also, how can I switch back to Java 1.7 when I'm done with it?

Answer

Appleman1234 picture Appleman1234 · Mar 18, 2014

I believe the commands you are looking for are alternatives --config java and alternatives --config javac. Additional documentation is here.