Install and Manage OpenJDK on CentOS

This section provides a tutorial example on how to install OpenJDK on CentOS 8 systems using 'dnf/yum' as the package manager.

The OpenJDK package is included as part of the CentOS 8 system by default. You don't need to install it yourself. But you can still install its additional modules using the "dnf" package manager.

1. Login as "herong", who has admin privileges.

2. Check the current installed version of OpenJDK:

herong$ java -version

openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

3. Find out where OpenJDK is installed. The output shows that OpenJDK packages are installed in the /usr/lib/jvm directory.

herong$ which java 
/usr/bin/java

herong$ ls -l /usr/bin/java 
lrwxrwxrwx. 1 root root 22 Jul 14  2020 /usr/bin/java -> /etc/alternatives/java

herong$ ls -l /etc/alternatives/java
lrwxrwxrwx. 1 root root 73 Jun 27  2021 /etc/alternatives/java 
  -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el8_4.x86_64/jre/bin/java

herong$ ls -l /usr/lib/jvm
drwxr-xr-x. Nov 13 2021 java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64
lrwxrwxrwx. Apr 30 2022 jre -> /etc/alternatives/jre
lrwxrwxrwx. Apr 30 2022 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx. Apr 30 2022 jre-1.8.0-openjdk 
  -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx. Nov 13 2021 jre-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64 
  -> java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/jre
lrwxrwxrwx. Apr 30 2022 jre-openjdk -> /etc/alternatives/jre_openjdk

4. Check the Java compiler module. The output shows that the Java compiler module is not installed.

herong$ javac
bash: javac: command not found...

5. Install java-1.8.0-openjdk-devel package, which contains the Java compiler module.

herong$ sudo dnf install java-1.8.0-openjdk-devel 

...
Installed:
  java-1.8.0-openjdk-1:1.8.0.312.b07-2.el8_5.x86_64      
  java-1.8.0-openjdk-devel-1:1.8.0.312.b07-2.el8_5.x86_64       
  ttmkfdir-3.0.9-54.el8.x86_64                           
  xorg-x11-fonts-Type1-7.5-19.el8.noarch                        

6. Verify the Java compiler module.

herong$ javac 
  javac 1.8.0_312

herong$ which javac 
  /usr/bin/javac

herong$ ls -l /usr/bin/javac 
  /usr/bin/javac -> /etc/alternatives/javac

herong$ ls -l /etc/alternatives/javac
  lrwxrwxrwx. 1 root root 70 Mar 31 22:43 /etc/alternatives/javac 
    -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/bin/javac

7. Check other OpenJDK 1.8 packages. You can install any of them if you want to.

herong$ sudo dnf search java-1.8.0

java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK 8 accessibility connector
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-headless-slowdebug.x86_64 : 
  OpenJDK 8 Runtime Environment unoptimised with full debugging on
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : 
  OpenJDK 8 API documentation compressed in a single archive
java-1.8.0-openjdk-slowdebug.x86_64 : 
  OpenJDK 8 Runtime Environment unoptimised with full debugging on
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle

Cool! I have the OpenJDK 1.8 installed with the Development Environment package which provides the Java compiler and other Java tools.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Process Management

 Files and Directories

 Running Apache HTTP Server (httpd) on Linux Systems

 Running Apache Tomcat on Linux Systems

 Running PHP Scripts on Linux Systems

 Running MySQL Database Server on Linux Systems

 Running Python Scripts on Linux Systems

 Conda - Environment and Package Manager

 GCC - C/C++ Compiler

OpenJDK - Open-Source JDK

Install and Manage OpenJDK on CentOS

 Upgrade OpenJDK on CentOS

 First Java Program - Hello.java

 Graphics Environments on Linux

 SquirrelMail - Webmail in PHP

 Tools and Utilities

 References

 Full Version in PDF/EPUB