Upgrade OpenJDK on CentOS

This section provides a tutorial example on how to upgrade OpenJDK on CentOS 8 systems using package manager 'dnf/yum' and symbolic link manager 'update-alternatives' symbolic links for 'java/javac' command.

If you want run Java applications that requires newer versions than Java 1.8 on CentOS 8 systems, you can upgrade OpenJDK to a newer version by following this tutorial.

1. Search for available OpenJDK packages. The output shows that the latest version is OpenJDK 17.

herong$ dnf search openjdk 

java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-...
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-...
java-17-openjdk.x86_64 : OpenJDK 17 Runtime Environment
java-17-openjdk-devel.x86_64 : OpenJDK 17 Development Environment
java-17-openjdk-...
...

2. Install the OpenJDK 17 JRE (java-17-openjdk) package.

herong$ sudo dnf install java-17-openjdk  

...
Installed:
  java-17-openjdk-1:17.0.1.0.12-2.el8_5.x86_64         
  java-17-openjdk-headless-1:17.0.1.0.12-2.el8_5.x86_64  

3. Install the OpenJDK 17 JDK (java-17-openjdk-devel) package.

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

...
Installed:
  java-17-openjdk-devel-1:17.0.1.0.12-2.el8_5.x86_64 

4. Verify the installation. The output shows that new OpenJDK 17 version is installed correctly. But it didn't update the "java" command with the newer version.

herong$ /usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64/bin/java -version 
  openjdk version "17.0.1" 2021-10-19 LTS
  OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS)
  OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing)

herong$ java -version 
  openjdk version "1.8.0_312"
  OpenJDK Runtime Environment (build 1.8.0_312-b07)
  OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

5. Update the "java" command using the "update-alternatives" tool. It allows you to select the newer version.

herong$ sudo update-alternatives --config java
  There is 2 programs that provide 'java'.
  -----------------------------------------------
  *+ 1   java-1.8.0-openjdk.x86_64 (
           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/jre/bin/java)
     2   java-17-openjdk.x86_64 (
           /usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64/bin/java)
  Enter to keep the current selection[+], or type selection number: 2

herong$ java -version 
  openjdk version "17.0.1" 2021-10-19 LTS
  OpenJDK Runtime Environment 21.9 (build 17.0.1+12-LTS)
  OpenJDK 64-Bit Server VM 21.9 (build 17.0.1+12-LTS, mixed mode, sharing)

6. Update the "javac" command using the "update-alternatives" tool.

herong$ sudo update-alternatives --config javac
  There is 2 programs that provide 'javac'.
  -----------------------------------------------
  *+ 1   java-1.8.0-openjdk.x86_64 (
           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-2.el8_5.x86_64/bin/javac)
     2   java-17-openjdk.x86_64 (
           /usr/lib/jvm/java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64/bin/javac)
  Enter to keep the current selection[+], or type selection number: 2

herong$ javac -version
  javac 17.0.1

Okay, I have the OpenJDK 17 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