Managing Java in Fedora or other RHEL-based systems

Managing Java in Fedora or other RHEL-based systems
Photo by Michiel Leunens / Unsplash

I'm a software developer and use Java quite a bit in my day-to-day tasks. Usually, IntelliJ IDEA handles java for me. However, sometimes I have to switch between Java versions, or install Java on a new machine. Here are the steps I've found to be most convenient on my Fedora install. It should also work on any RHEL-based system!


1. Installing the Latest Java Version

Let's kick off with installing the latest OpenJDK version using the terminal:

sudo dnf install java-latest-openjdk java-latest-openjdk-devel

2. Exploring Available Versions

The command below will reveal the OpenJDK versions you can opt for:

dnf search openjdk

If you fancy installing a specific version, say Java 11, use:

sudo dnf install java-11-openjdk.x86_64

3. Verifying the Installation

Once installed, ensure everything's in place by checking the Java version:

java --version

4. Version switching

To juggle between installed versions seamlessly, use sudo alternatives --config java. This command allows you to choose the default Java executable by selecting a number. Confirm your choice's effectiveness by checking java -version.

Whether you're diving into the latest features or maintaining compatibility, these commands will keep you in control of your Java destiny.

That's all!