Install Java 11 Centos 7

admin13 April 2024Last Update :

Understanding Java 11 and CentOS 7 Compatibility

Before diving into the installation process, it’s crucial to understand the compatibility between Java 11 and CentOS 7. Java 11 is a long-term support (LTS) release from Oracle, which means it will receive updates for an extended period. CentOS 7, on the other hand, is a stable, predictable, manageable, and reproducible platform derived from the sources of Red Hat Enterprise Linux (RHEL). Ensuring that your system meets the requirements for Java 11 is the first step towards a successful installation.

Prerequisites for Installing Java 11 on CentOS 7

To install Java 11 on CentOS 7, you need to have a user account with sudo privileges to execute administrative commands. Additionally, ensure that your system is up-to-date by running the following command:

yum update

This will update all your system packages to their latest versions, reducing the risk of compatibility issues during the Java installation.

Installing Java 11 on CentOS 7

Option 1: Install OpenJDK 11

OpenJDK (Open Java Development Kit) is an open-source implementation of the Java Platform, Standard Edition. To install OpenJDK 11 on CentOS 7, follow these steps:

  • First, search for the available OpenJDK 11 packages using the command:
    yum search java-11-openjdk
  • Install the package by executing:
    sudo yum install java-11-openjdk-devel
  • Verify the installation by checking the Java version:
    java -version

The output should display the installed version of OpenJDK, confirming that Java 11 is now installed on your system.

Option 2: Install Oracle JDK 11

Oracle JDK offers a different build of Java 11 with commercial support. To install Oracle JDK 11, you’ll need to download it directly from Oracle’s website and manually set it up on your CentOS 7 system.

  • Download the Oracle JDK 11 .rpm package from the official Oracle website.
  • Once downloaded, install the package using the RPM command:
    sudo rpm -ivh jdk-11*.rpm
  • Set Oracle JDK 11 as the default Java version by updating the alternatives system:
    sudo alternatives --config java
  • Select the appropriate version when prompted.
  • Confirm the installation by checking the Java version:
    java -version

You should see the Oracle JDK 11 version in the output, indicating a successful installation.

Configuring Java Environment Variables

Setting up environment variables such as JAVA_HOME and updating the PATH variable is essential for some applications to function correctly.

  • Determine the path of your Java installation:
    sudo update-alternatives --config java
  • Copy the installation paths of your preferred Java version.
  • Edit the /etc/profile file to set the JAVA_HOME variable:
    sudo vi /etc/profile
  • Add the following lines at the end of the file, replacing the path with your Java installation path:
    export JAVA_HOME="/usr/lib/jvm/java-11-openjdk"
    export PATH=$PATH:$JAVA_HOME/bin
  • Source the profile file to apply the changes immediately:
    source /etc/profile
  • Verify that the JAVA_HOME variable is set correctly:
    echo $JAVA_HOME

The output should show the path you added to the /etc/profile file.

Managing Multiple Java Versions

If you have multiple Java versions installed on your CentOS 7 system, you can manage them using the alternatives system.

  • To configure the default Java version, use:
    sudo alternatives --config java
  • Select the version you want to use by typing the selection number.
  • Repeat the process for javac if necessary:
    sudo alternatives --config javac

This allows you to switch between different Java versions easily.

Troubleshooting Common Java Installation Issues on CentOS 7

During the installation process, you might encounter various issues. Here are some common problems and their solutions:

  • If you face dependency issues while installing Java, try clearing the YUM cache with:
    sudo yum clean all
  • In case of conflicts with older Java versions, remove them before installing Java 11:
    sudo yum remove java-1.*
  • Ensure that firewalls or network policies are not blocking access to Oracle’s website if you’re unable to download the Oracle JDK.

Frequently Asked Questions

How do I uninstall Java 11 from CentOS 7?

To uninstall Java 11, you can use the yum or rpm command depending on how it was installed:

sudo yum remove java-11-openjdk-devel


sudo rpm -e jdk-11*

Can I install Java 11 on CentOS 7 without root access?

Without root access, you cannot use the yum or rpm commands to install Java globally. However, you can still download the tar.gz version of Java and extract it to your home directory, setting the environment variables locally.

Is Java 11 free to use?

OpenJDK 11 is free to use under the GNU General Public License (GPL). Oracle JDK 11 is also free for development and testing, but you may need to pay for commercial use or support.

Do I need to restart my CentOS 7 system after installing Java 11?

A system restart is not required after installing Java 11. However, you need to log out and log back in or source the profile file to apply the new environment variables.

How can I ensure that my Java application uses Java 11?

Make sure that the JAVA_HOME environment variable points to your Java 11 installation and that the PATH variable includes $JAVA_HOME/bin. This ensures that your Java application uses the correct Java version.


Leave a Comment

Your email address will not be published. Required fields are marked *

Comments Rules :

Breaking News