3.3. Install OpenJDK on Red Hat Enterprise Linux
OpenJDK is one of many Java Development Kits (JDKs) supported in Red Hat Enterprise Linux for use with JBoss enterprise products. This task shows you how to install OpenJDK in Red Hat Enterprise Linux, and how to configure your system to use it as the default JDK.
You must meet the following conditions before continuing with this task:
- You must be running Red Hat Enterprise Linux 6. OpenJDK is not available or supported for Red Hat Enterprise Linux 5 at this time.
- The server running Red Hat Enterprise Linux 6 must be registered with RHN and subscribed to the base channel. Refer to the Package Management section of the Red Hat Enterprise Linux 6 Deployment Guide on https://access.redhat.com/knowledge/docs/ for more information about managing subscriptions and entitlements on Red Hat Enterprise Linux systems.
Install the OpenJDK RPM.There are two different ways to install an RPM, depending on whether you have used a command-line interface (CLI) or a Graphical User Interface (GUI).
From the CLIAfter logging in with administrator access, run one of the following two commands:
- OpenJDK 6
yum install java-1.6.0-openjdk-devel
- OpenJDK 7
yum install java-1.7.0-openjdk-devel
From a GUI
- In Gnome, select Administration from the System menu, and click Add / Remove Software.
- Search for
openjdkand choose the
java-1.6.0-openjdk-develoption for OpenJDK 6 or the
java-1.7.0-openjdk-develoption for OpenJDK 7.
- Click Apply to install the selected packages and dependencies.
- When prompted, enter the administrator password to install the packages.
Optional: Set the
JAVA_HOMEenvironment variable.Some applications such as Apache Maven and Apache Ant require you to set the
JAVA_HOMEenvironment variable. If you need to do this, follow these steps.
- Determine the correct value for
JAVA_HOME. Red Hat Enterprise Linux installs OpenJDK 1.6 into either
/usr/lib/jvm/java-1.6.0-openjdk-188.8.131.52.x86_64/, depending on whether your system is a 32-bit or 64-bit architecture. The
JAVA_HOMEshould point to the directory containing a
- As the user who will use OpenJDK, open the shell configuration file. For the Bash shell, this file is
- At the bottom of the file, type the following line, replacing the hypothetical path with the actual path to use on your own system:
- Save the file, and log out of and back into your session.
Switch between different OpenJDK versions using the
alternativesutility.Red Hat Enterprise Linux includes a utility called
alternatives, which lets you change the default version for applications which allow multiple versions to be installed. OpenJDK is one such application.To use the
alternativesutility, perform the following steps. Note that setting the environment variables overrides the behavior of the
alternativescommand. For instance, if you use a script which manually sets
$JAVAvariables to a different JDK from the one specified by the
alternativescommand, the environment variables will override the command.
- Log in as the
rootuser, or prefix the commands below with the
alternativescommand is not installed by default, but may already be installed on your system. If not, install the
alternativespackage by running the following command:
yum install alternatives
- Issue the following command:
/usr/sbin/alternatives --config java
- Follow the prompts that follow to set the default version of OpenJDK.
OpenJDK is installed on your server and available for your use. If necessarily, the
JAVA_HOME environment variable has been specified as well. If necessary, the default OpenJDK for your system has been set using the