Change JDK in /etc/alternatives

I installed JDK 1.6.0_31 on a Linux server with an existing OpenJDK 1.6 install. The version from Oracle is preferred, and more stable, so I wanted to switch versions. Since the installation is managed, for lack of a better term, in /etc/alternatives changing the binary path wasn’t the way to go. Here are the commands to change the entries in /etc/alternatives.

First, add the reference to the new java via the –install option
alternatives --install /usr/bin/java java /usr/jdk64/jdk1.6.0_31/bin/java 3
The “3″ at the end of the command represents the priority of the command in the list maintained by alternatives. For a new install, this is set to 1.

Then run the following command and select the version you want to use. In our case, this was the third option.
alternatives --config java

I then updated /etc/alternatives for javac and jar as well.
alternatives --install /usr/bin/javac javac /usr/jdk64/jdk1.6.0_31/bin/javac 1
alternatives --install /usr/bin/jar jar /usr/jdk64/jdk1.6.0_31/bin/jar 1

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>