B.6. Setting the default JDK with the alternatives Utility
The alternatives utility serves for managing different software packages that provide the same functionality. Red Hat Enterprise Linux uses alternatives to ensure that only one Java Development Kit is set as the system default at one time.
Important
Installing a Java Development Kit from the Red Hat Network will normally result in an automatically configured system. However, if multiple JDKs are installed, it is possible that
/usr/sbin/alternatives
may contain conflicting configurations. Refer to Procedure B.5, “ Using alternatives to Set the Default JDK ” for syntax of the alternatives
command.
Procedure B.5. Using alternatives to Set the Default JDK
Become the root user.
The alternatives utility needs to be run with root privileges. Use thesu
command or other mechanism to gain these privileges.Set
java
.Run the following command:/usr/sbin/alternatives --config java
Next, follow the on-screen directions to ensure that the correct version ofjava
is selected. Table B.1, “java
alternative commands” shows the relevant command settings for each of the different JDKs.Table B.1. java alternative commands JDK alternative command OpenJDK 1.6 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
Sun Microsystems JDK 1.6 /usr/lib/jvm/jre-1.6.0-sun/bin/java
Set
javac
.Enter this command:/usr/sbin/alternatives --config javac
Follow the on-screen directions to ensure that the correct version ofjavac
is selected. Table B.2, “javac
alternative commands” shows the appropriate command settings for the different JDKs.Table B.2. javac alternative commands JDK alternative command OpenJDK 1.6 /usr/lib/jvm/java-1.6.0-openjdk/bin/javac
Sun Microsystems JDK 1.6 /usr/lib/jvm/java-1.6.0-sun/bin/javac
Extra Step: Set
java_sdk_1.6.0
.The Sun Microsystems JDK 1.6 requires an additional command be run:/usr/sbin/alternatives --config java_sdk_1.6.0
Follow the on-screen directions to ensure that the correctjava_sdk
is selected. It is/usr/lib/jvm/java-1.6.0-sun
.