
The Ultimate Guide to Installing and Configuring OpenJDK 13 on CentOS 8
Java remains a cornerstone of enterprise application development, powering countless systems worldwide. For developers and system administrators working with CentOS 8, having a stable and up-to-date Java Development Kit (JDK) is essential. OpenJDK, the open-source implementation of the Java Platform, is the standard choice for most Linux distributions, offering robust performance and excellent integration.
This guide provides a comprehensive, step-by-step walkthrough for installing and configuring OpenJDK 13 on your CentOS 8 system. We’ll cover everything from the initial installation to managing multiple versions and setting up crucial environment variables.
Prerequisites
Before you begin, ensure you have the following:
- A system running CentOS 8.
- Access to a user account with
sudo
or root privileges.
Step 1: Installing OpenJDK 13
CentOS 8 uses the dnf
package manager, which makes installing software straightforward and reliable. We will use it to install OpenJDK 13 directly from the default CentOS repositories.
First, open your terminal and run the following command to install the package:
sudo dnf install java-13-openjdk
The dnf
package manager will automatically resolve and install all necessary dependencies. When prompted, type y
and press Enter to confirm the installation.
That’s it! The JDK is now installed on your system. The package includes both the Java Runtime Environment (JRE) for running applications and the development tools (like the compiler) needed for building them.
Step 2: Verifying the Installation
Once the installation is complete, it’s crucial to verify that the correct version of Java is active on your system. You can do this with a simple command that checks the installed version:
java -version
If the installation was successful, you should see output similar to this, confirming that OpenJDK 13 is ready to use:
openjdk version "13.0.2" 2020-01-14
OpenJDK Runtime Environment (build 13.0.2+8)
OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
Seeing this output confirms that OpenJDK 13 is successfully installed and is the default Java version on your system.
Managing Multiple Java Versions (Optional)
In many development or production environments, you might need to have multiple versions of Java installed simultaneously. CentOS uses the alternatives
utility to manage which version is the system-wide default.
If you have other Java versions installed, you can list them and select your preferred default with this command:
sudo alternatives --config java
This command will present you with a list of all installed Java executables. You can simply enter the selection number corresponding to OpenJDK 13 to set it as the default. If you only have one version installed, the system will inform you that there is nothing to configure.
Step 3: Setting the JAVA_HOME Environment Variable
Many Java-based applications, including popular tools like Maven, Tomcat, and Jenkins, rely on the JAVA_HOME
environment variable to locate the Java installation directory. While not always required for simple applications, setting JAVA_HOME
is a critical best practice for ensuring compatibility and proper function.
Find the Java Installation Path
First, we need to find the symbolic link path for our OpenJDK 13 installation using the
alternatives
utility:sudo alternatives --config java
Look at the path for your chosen Java version. We want to find the root directory of the JDK, which is typically located in
/usr/lib/jvm/
. For OpenJDK 13, the path will look something like this:/usr/lib/jvm/java-13-openjdk-13.0.2.8-4.el8_1.x86_64
Set the Variable System-Wide
To set the
JAVA_HOME
variable for all users, the recommended approach is to create a new script file in the/etc/profile.d/
directory.Create a new file named
java.sh
:sudo nano /etc/profile.d/java.sh
Add the following lines to the file. Be sure to replace the path with the actual path you found in the previous step.
export JAVA_HOME="/usr/lib/jvm/java-13-openjdk-13.0.2.8-4.el8_1.x86_64" export PATH=$PATH:$JAVA_HOME/bin
Save the file and exit the editor. The second line adds the Java
bin
directory to the system’sPATH
, ensuring you can run Java commands from anywhere.Apply the Changes
Make the script executable and then load it into the current shell session using the
source
command:sudo chmod +x /etc/profile.d/java.sh source /etc/profile.d/java.sh
This new environment variable will be loaded automatically for all users upon their next login.
Verify the
JAVA_HOME
VariableFinally, confirm that the variable has been set correctly by echoing its value:
echo $JAVA_HOME
The output should display the path you just configured.
Important Security Tip: Keep Java Updated
Java is a frequent target for security vulnerabilities. One of the most important security practices is to keep your JDK installation patched and up-to-date. Because we installed OpenJDK using the dnf
package manager, keeping it updated is simple.
Regularly run the following command to apply the latest security patches and updates to your system, including the OpenJDK package:
sudo dnf update
Conclusion
You have now successfully installed and configured OpenJDK 13 on your CentOS 8 server. By verifying the installation and setting the JAVA_HOME
environment variable, you have created a stable and reliable environment for running and developing Java applications. Following these steps ensures your system is properly set up for any Java-based project you tackle next.
Source: https://kifarunix.com/install-oracle-java-openjdk-13-on-centos-8/