19

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?

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137

1 Answers1

48

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

Neji Soltani
  • 1,522
  • 4
  • 22
  • 41
Appleman1234
  • 15,946
  • 45
  • 67
  • Ok, great. This is exactly what I was looking for. Thanks. Regarding the pertinence of this question over here, sorry: I wasn't aware. I'll accept the question so that you can do all you need to do to migrate where appropriate. – Olivier Grégoire Mar 18 '14 at 11:08
  • I can not believe how easy it is to do this in Linux. In windows I have to make changes to the registry in order to get this done, and it only works for the java within the same version. Linux just critical strike windows for unlimited damage on this one! – Harvey Lin Jun 12 '18 at 23:36
  • How can you do this without it prompting for user input, I need to change versions as part of a docker build – Kodi Nov 14 '22 at 23:16
  • @Kodi, See https://serverfault.com/questions/123419/linux-alternatives-config-without-user-input for more information – Appleman1234 Nov 15 '22 at 03:10