How to Change Java Version on Oracle Linux 8

I had Java 8 on my Oracle Linux 8 machine but I wanted to change it to Open JDK 11. Here is what I did. The following instruction will probably work for RedHat descendants.

First, I had to find a way to install Open JDK. I ran the following command to get the right package information.

dnf search java-11

Here is the result.

java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk.src : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime
                                : Environment
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation
                                   : compressed in a single archive
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static
                                   : linking

To install Open JDK 11, run the following command.

sudo dnf install java-11-openjdk.x86_64

Now I want to switch my default Java version to the one I just installed.

sudo alternatives --config java

alternatives lists the available Java installations and it gives you options to select from.

Once you make the selection, check the default Java version like the following.

java -version

Result:

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

Author: admin

A software engineer in greater Seattle area

Leave a Reply

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