3.3. Install OpenJDK on Red Hat Enterprise Linux
Introduction
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.Note
It is possible to install multiple JDKs on a single system.
Task Prerequisites
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 CLI
After 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
openjdk
and choose thejava-1.6.0-openjdk-devel
option for OpenJDK 6 or thejava-1.7.0-openjdk-devel
option 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_HOME
environment variable.Some applications such as Apache Maven and Apache Ant require you to set theJAVA_HOME
environment 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-1.6.0.0/
or/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/
, depending on whether your system is a 32-bit or 64-bit architecture. TheJAVA_HOME
should point to the directory containing abin/java
executable. -
As the user who will use OpenJDK, open the shell configuration file. For the Bash shell, this file is
/home/
.username
/.bashrc -
At the bottom of the file, type the following line, replacing the hypothetical path with the actual path to use on your own system:
export JAVA_HOME="
/path/to/java/home
" -
Save the file, and log out of and back into your session.
-
-
Switch between different OpenJDK versions using the
alternatives
utility.Red Hat Enterprise Linux includes a utility calledalternatives
, which lets you change the default version for applications which allow multiple versions to be installed. OpenJDK is one such application.To use thealternatives
utility, perform the following steps. Note that setting the environment variables overrides the behavior of thealternatives
command. For instance, if you use a script which manually sets$JAVA_HOME
and$JAVA
variables to a different JDK from the one specified by thealternatives
command, the environment variables will override the command.-
Log in as the
root
user, or prefix the commands below with thesudo
command. -
The
alternatives
command is not installed by default, but may already be installed on your system. If not, install thealternatives
package 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.
-
Result:
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 alternatives
utility.Set JAVA_HOME
Ensure all users have their JAVA_HOME environment variable set to the correct value:
echo "export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64" > /etc/profile.d/java_home.sh