Appendix A. Installing a Java Development Kit on Red Hat Enterprise Linux

Follow these instructions to install a Java Development Kit (JDK) on Red Hat Enterprise Linux using Red Hat Network (RHN).
If you have difficulties performing the installation using RHN please refer to the RHN Help Desk at https://rhn.redhat.com/rhn/help/ or contact Red Hat Support directly for assistance.

Important

The following procedure require that the commands be run with administrator privileges. This means running the commands using the sudo command, logging in as the root user, or by switching to the root user with the su command.

A.1. OpenJDK on Red Hat Enterprise Linux 5

Use this procedure to install OpenJDK on Red Hat Enterprise Linux 5.

Procedure A.1. Installing OpenJDK on Red Hat Enterprise Linux 5

  1. Subscribe to the base channel

    The OpenJDK is available in the RHN base channel. By default, all installations of Red Hat Enterprise Linux are subscribed to this channel.
  2. Install the Package

    Use the yum utility to install OpenJDK:
    [localhost]# yum install java-1.6.0-openjdk-devel
  3. Verify System Default JDK

    To ensure that the correct JDK is set as the system default, run the alternatives command as described in Section A.4, “Setting the Default JDK with the alternatives Utility”

A.2. Oracle Java Development Kit on Red Hat Enterprise Linux 5

Use this procedure to install the Oracle Java Development Kit (JDK) on Red Hat Enterprise Linux 5.

Procedure A.2. Installing the Oracle JDK on Red Hat Enterprise Linux 5

  1. Subscribe to Supplementary Server channel

    The Oracle JDK is available in the Supplementary Server channel. One will need to ensure that the machine is subscribed to this channel in order to install this package.
  2. Install the Package

    Use the yum command to install the Oracle JDK package:
    [localhost]# yum install java-1.6.0-sun-devel
  3. Verify System Default JDK

    To ensure that the intended JDK is set as the system default, run the alternatives command as described in Section A.4, “Setting the Default JDK with the alternatives Utility”

A.3. Installing the Oracle JDK on Red Hat Enterprise Linux AS/ES 4

Use this procedure to install the Oracle Java Development Kit on Red Hat Enterprise Linux AS or ES 4.

Procedure A.3. Installing the Oracle JDK on Red Hat Enterprise Linux AS/ES 4

  1. Subscribe to the Extras Channel

    The Oracle Java Development Kit is available in the Red Hat Extras channel. Ensure that the machine is subscribed to this channel in order to install this package.
  2. Install using up2date

    Run this command to install the package:
    [localhost] up2date java-1.6.0-sun-devel
  3. Check That it is the System's Default Java Development Kit

    To ensure that the intended JDK is set as the system default, run the alternatives command as described in Section A.4, “Setting the Default JDK with the alternatives Utility”

A.4. Setting the Default JDK with the alternatives Utility

alternatives is a tool for managing different software packages that provide the same functionality. Red Hat Enterprise Linux uses alternatives to ensure that only one Java Development Kit (JDK) is set as default at a time.
Installing a JDK from Red Hat Network will normally result in an automatically configured system. However, if you have installed multiple JDKs it is possible that there may be conflicts. Perform the following steps to verify that the everything is set up correctly.

Example A.1. Using alternatives to Configure the Default Java Development Kit

[localhost]# /usr/sbin/alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java

Enter to keep the current selection[+], or type selection number:

Procedure A.4.  Using alternatives to Set the Default JDK

  1. Set java

    Input this command: /usr/sbin/alternatives --config java
    Next, follow the on-screen directions to ensure that the correct version of java is selected. Table A.1, “java alternative commands” shows the relevant command settings for each of the different JDKs.

    Table A.1. java alternative commands

    JDK alternative command
    OpenJDK 1.6 /usr/lib/jvm/jre-1.6.0-openjdk/bin/java
    Oracle JDK 1.6 /usr/lib/jvm/jre-1.6.0-sun/bin/java

  2. Set javac

    Enter this command: /usr/sbin/alternatives --config javac
    Follow the on-screen directions to ensure that the correct version of javac is selected. Table A.2, “javac alternative commands” shows the appropriate command settings for the different JDKs.

    Table A.2. javac alternative commands

    JDK alternative command
    OpenJDK 1.6 /usr/lib/jvm/java-1.6.0-openjdk/bin/javac
    Oracle JDK 1.6 /usr/lib/jvm/java-1.6.0-sun/bin/javac

  3. Extra Step: Set java_sdk_1.6.0

    The Oracle 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 correct java_sdk is selected. It is /usr/lib/jvm/java-1.6.0-sun.