Red hat enterprise linux java

Chapter 2. Installing OpenJDK 11 on Red Hat Enterprise Linux

OpenJDK is an environment for developing and running a wide range of platform-agnostic applications, from mobile applications to desktop and web applications and enterprise systems. Red Hat provides an open source implementation of the Java Platform SE (Standard Edition) called OpenJDK.

Applications are developed using the JDK (Java Development Kit). Applications are run on a JVM (Java Virtual Machine), which is included in the JRE (Java Runtime Environment) and the JDK. There is also a headless version of Java which has the smallest footprint and does not include the libraries needed for a user interface. The headless version is packaged in the headless subpackage.

If you are unsure whether you need the JRE or the JDK, it is recommended that you install the JDK.

The following sections provide instructions for installing OpenJDK on Red Hat Enterprise Linux.

You can install multiple major versions of OpenJDK on your local system. If you need to switch from one major version to another major version, issue the following command in your command-line interface (CLI) and then follow the onscreen prompts:

$ sudo update-alternatives --config 'java'

2.1. Installing a JRE on RHEL by using yum

You can install OpenJDK Java Runtime Environment (JRE) using the system package manager, yum .

Prerequisites

  • Logged in as a user with root privileges on the system.
  • Registered your local system to your Red Hat Subscription Management account. See the Registering a system using Red Hat Subscription Management user guide.

    Run the yum command, specifying the package you want to install:

$ sudo yum install java-11-openjdk
$ java -version openjdk version "11.0.14" 2022-01-18 LTS LTS OpenJDK Runtime Environment 18.9 (build 11.0.14+9-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.14+9-LTS, mixed mode, sharing)

If the output from the previous command shows that you have a different major version of OpenJDK checked out on your system, you can enter the following command in your CLI to switch your system to use OpenJDK 11:

$ sudo update-alternatives --config 'java'

2.2. Installing a JRE on RHEL by using an archive

You can install OpenJDK Java Runtime Environment (JRE) using an archive. This is useful if the Java administrator does not have root privileges.

Читайте также:  Samsung 3205 драйвер linux

To ease the upgrades for later versions create a parent directory to contain your JREs and create a symbolic link to the latest JRE using a generic path.

    Create a directory to where you want to download the archive file, and then navigate to that directory on your command-line interface (CLI). For example:

$ tar -xf java-11-openjdk-11.0.14.0.9-3.portable.jre.el.x86_64.tar.xz -C ~/jres
$ ln -s ~/jres/java-11-openjdk-11.0.14.0.9-3.portable.jre.el.x86_64 ~/jres/java-11
$ export JAVA_HOME=~/jres/java-11
$ printenv | grep JAVA_HOME JAVA_HOME=~/jres/java-11
$ export PATH="$JAVA_HOME/bin:$PATH"
$ java -version openjdk version "11.0.14" 2022-01-18 LTS OpenJDK Runtime Environment 18.9 (build 11.0.14+9-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.14+9-LTS, mixed mode, sharing)

You can ensure that JAVA_HOME environment variable persists for the current user by exporting the environment variable in ~/.bashrc .

2.3. Installing OpenJDK on RHEL by using yum

You can install OpenJDK using the system package manager, yum .

Prerequisites

  • Log in as a user with root privileges.
  • Registered your local system to your Red Hat Subscription Management account. See the Registering a system using Red Hat Subscription Management user guide.

    Run the yum command, specifying the package you want to install:

$ sudo yum install java-11-openjdk-devel
$ javac -version javac 11.0.14

2.4. Installing OpenJDK on RHEL by using an archive

You can install OpenJDK with an archive. This is useful if the Java administrator does not have root privileges.

To ease upgrades, create a parent directory to contain your JREs and create a symbolic link to the latest JRE using a generic path.

    Create a directory to where you want to download the archive file, and then navigate to that directory on your command-line interface (CLI). For example:

$ tar -xf java-11-openjdk-11.0.14.0.9-3.portable.jdk.el.x86_64.tar.xz -C ~/jdks
$ ln -s ~/jdks/java-11-openjdk-11.0.14.0.9-3.portable.jdk.el.x86_64 ~/jdks/java-11
$ export JAVA_HOME=~/jdks/java-11
$ printenv | grep JAVA_HOME JAVA_HOME=~/jdks/java-11
$ export PATH="$JAVA_HOME/bin:$PATH"
$ java -version openjdk version "11.0.14" 2022-01-18 LTS OpenJDK Runtime Environment 18.9 (build 11.0.14+9-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.14+9-LTS, mixed mode, sharing)

You can ensure that JAVA_HOME environment variable persists for the current user by exporting the environment variable in ~/.bashrc .

2.5. Installing multiple major versions of OpenJDK on RHEL by using yum

You can install multiple versions of OpenJDK by using the system package manager, yum .

Prerequisites

  • A Red Hat Subscription Management (RHSM) account with an active subscription that provides access to a repository that provides the OpenJDK you want to install.
  • You must have root privileges on the system.
Читайте также:  Кириллица в консоли linux

    Run the following yum commands to install the package: For OpenJDK 17

$ sudo yum install java-17-openjdk
$ sudo yum install java-11-openjdk
$ sudo yum install java-1.8.0-openjdk
$ sudo yum list installed "java*" Installed Packages java-1.8.0-openjdk.x86_64 1:1.8.0.322.b06-2.el8_5 @rhel-8-for-x86_64-appstream-rpms java-11-openjdk.x86_64 1:11.0.14.0.9-2.el8_5 @rhel-8-for-x86_64-appstream-rpms java-17-openjdk.x86_64 1:17.0.2.0.8-4.el8_5 @rhel-8-for-x86_64-appstream-rpms
$ java -version openjdk version "11.0.14" 2022-01-18 LTS OpenJDK Runtime Environment 18.9 (build 11.0.14+9-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.14+9-LTS, mixed mode, sharing)

If the output from the previous command shows that you have a different major version of OpenJDK checked out on your system, you can enter the following command in your CLI to switch your system to use OpenJDK 11:

$ sudo update-alternatives --config 'java'

Additional resources

2.6. Installing multiple major versions of OpenJDK on RHEL by using an archive

You can install multiple major versions of OpenJDK by using the same procedures found in Installing a JRE on RHEL by using an archive or Installing OpenJDK on RHEL 11 by using an archive using multiple major versions .

For instructions how to configure the default OpenJDK version for the system, see Interactively selecting a system-wide OpenJDK version on RHEL.

Additional resources

2.7. Installing multiple minor versions of OpenJDK on RHEL by using yum

You can install multiple minor versions of OpenJDK on RHEL. This is done by preventing the installed minor versions from being updated.

Prerequisites

    Add the installonlypkgs option in /etc/yum.conf to specify the OpenJDK packages that yum can install but not update.

$ installonlypkgs=java- --openjdk,java- --openjdk-headless,java- --openjdk-devel
$ rpm -qa | grep java-11-openjdk java-11-java-11-openjdk-11.0.13.0.8-1.el8_5.x86_64 java-11-openjdk-11.0.14.0.9-2.el8_5.x86_64
$ /usr/lib/jvm/java-11-openjdk-11.0.14.0.9-2.el8_5.x86_64/bin/java -version openjdk version "11.0.14" 2022-01-18 LTS OpenJDK Runtime Environment 18.9 (build 11.0.14+9-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.14+9-LTS, mixed mode, sharing) $ /usr/lib/jvm/java-11-java-11-openjdk-11.0.13.0.8-1.el8_5.x86_64/bin/java -version openjdk version ""11.0.13" 2021-10-19 LTS OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)

2.8. Installing multiple minor versions of OpenJDK on RHEL by using an archive

Installing multiple minor versions is the same as Installing a JRE on RHEL by using an archive or Installing OpenJDK on RHEL 11 by using an archive using multiple minor versions.

For instructions how to choose a default minor version for the system, see Non-interactively selecting a system-wide OpenJDK version on RHEL.

Additional resources

Источник

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.

Читайте также:  Добавить linux при загрузке windows

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.

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).

In Gnome, select Administration from the System menu, and click Add / Remove Software .

Search for openjdk and choose the java-1.6.0-openjdk-devel option for OpenJDK 6 or the java-1.7.0-openjdk-devel option for OpenJDK 7.

Some applications such as Apache Maven and Apache Ant require you to set the JAVA_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. The JAVA_HOME should point to the directory containing a bin/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 replaceable»>/path/to/java/home«

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 alternatives utility, perform the following steps. Note that setting the environment variables overrides the behavior of the alternatives 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 the alternatives command, the environment variables will override the command.

The alternatives command is not installed by default, but may already be installed on your system. If not, install the alternatives package by running the following command:

/usr/sbin/alternatives --config java

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.

Источник

Оцените статью
Adblock
detector