Fedora

How to Install OpenJDK on Fedora Linux

Java is a general-purpose programming language offering reliability, security, and compatibility. Java is everywhere – mobile apps, desktop programs, web applications, and enterprise systems.

To build Java apps, developers need the JDK (Java Development Kit) that comes with all the essential tools. In this guide, check out how to install OpenJDK on Fedora Linux.

JDK and OpenJDK

Before jumping into the OpenJDK installation process, here’s a quick refresh of JRE versus JDK.

JRE (Java Runtime Environment)

One of the key concepts that make Java awesome is “write once; run anywhere.” This is where JRE comes in.

When compiled, a Java program is transformed into bytecodes. It’s the job of the JRE to create a virtual environment in which this bytecode will run. The virtual environment is known as JVM (Java Virtual Machine).

As long as a platform has a JRE built for it, it’s possible to run Java apps.

For general users, having JRE installed is more than enough.

JDK (Java Development Kit)

The JDK is the software development environment for developing Java apps and applets. It’s a combination of multiple packages. The JDK includes the JRE, an interpreter, a compiler, a documentation generator, and other tools.

As the description suggests, JDK is necessary for developers working with Java.

There are multiple JDKs available to choose from – OpenJDK, Oracle JDK, AdoptOpenJDK, etc.

Oracle JDK vs. OpenJDK

Oracle maintains Java itself. Starting from Java 11, Oracle changed the Java licensing policy that caused quite a commotion in the community and market.

Previously, Oracle offered free updates (security patches, hotfixes, etc.) to the older Java (Oracle JDK) versions. These hotfixes would also be included in the OpenJDK codebase. Starting from Java 11, Oracle changed the Java release cycle and stopped offering patches to the old versions for free. If there was support necessary, then it requires purchasing a license from Oracle.

Moreover, Oracle JDK isn’t to be used for professional workload anymore. If Oracle JDK is to be used, then it also requires getting a license from Oracle. However, for educational and personal use, Oracle JDK is still available, free of charge.

Using OpenJDK offers more freedom. OpenJDK is more than enough for personal and educational use. If the older versions of OpenJDK to be used, it’s also fine. However, that comes with security concerns. Because of Oracle’s new release cycle, a new OpenJDK will also become obsolete very soon. For many businesses, that’s not a viable solution.

OpenJDK vs AdoptOpenJDK

This is where AdoptOpenJDK comes in. It’s a community release of the OpenJDK. It improvises where OpenJDK lacks.

In the case of OpenJDK, older Java comes with the threat of security issues. Those patches are only available on the latest Java. AdoptOpenJDK backports those improvements to the older versions, offering a more consistent experience for the businesses.

AdoptOpenJDK is also enterprise-ready. It’s sponsored by major powerhouses of the industry, namely Amazon, IBM, Microsoft, Red Hat, etc.

As for licensing, AdoptOpenJDK is also flexible. It uses an OpenJDK source that’s licensed under GPL v2 with Classpath Exception. The build scripts and other codes related to AdoptOpenJDK is licensed under Apache License v2.0. Check out AdoptOpenJDK to learn more.

For personal and educational purposes, either is fine.

Installing OpenJDK on Fedora

OpenJDK is an open-source implementation of the Java Standard Edition (Java SE) and JDK. It’s the source code of OpenJDK that builds the basis of all the commercial Java products, including Oracle JDK. OpenJDK is publicly available under the GNU General Public License.

The OpenJDK package is directly available from the official Fedora repo. It contains all the major Java versions. At the time of writing this article, OpenJDK is available for Java 8, Java 11 (LTS), and Java 15 (latest).

To get a list of all the available OpenJDK versions, run the following command.

$ dnf search openjdk

It’s recommended to go with the long-term release. In this example, the following command will install Java 11, the latest LTS release. There

$ sudo dnf install java-11-openjdk-devel.x86_64

To install the latest Java, run the following command. Note that this command applies to any latest Java release. As of now, the latest Java version is Java 15.

$ sudo dnf install java-latest-openjdk-devel.x86_64

Verify the installation.

$ java -version

$ javac -version

Install AdoptOpenJDK

While the default OpenJDK is fine, AdoptOpenJDK offers more features and flexibility for everyone. There are two ways to install AdoptOpenJDK.

Install AdoptOpenJDK from the archive

First, grab the appropriate version of AdoptOpenJDK. Check out AdoptOpenJDK latest releases page.

Extract the archive.

$ tar -xvf OpenJDK11U-jdk_x64_linux_hotspot_11.0.9.1_1.tar.gz

Add the location of the newly extracted directory to “PATH.” To make it a permanent change, add the line to bashrc.

$ nano ~/.bashrc
$ export PATH=/home/viktor/Downloads/jdk-11.0.9.1+1/bin:$PATH

Verify that the installation was successful.

$ java -version
$ javac -version

Install AdoptOpenJDK RPM

This is the recommended way of installing AdoptOpenJDK. Instead of manual installation, it’s better to let the package manager do the job.

Downloading the RPM package for Fedora is not intuitive. First, go to the link that hosts AdoptOpenJDK RPM packages for Fedora.

Select the current version of Fedora your system is currently running. In my case, it’s Fedora 33.

Go to the “x86_64” folder.

As we’re interested in grabbing the RPM package, select the “Packages” folder.

Download the AdoptOpenJDK RPM package of your choice. The packages are named after their Java version, JVM type, etc. As we’re going for the JDK, skip grabbing any JRE package.

Once downloaded, install the RPM package.

$ sudo dnf localinstall adoptopenjdk-11-hotspot-11.0.9+11.2-3.x86_64.rpm

Install AdoptOpenJDK using SDKMAN

SDKMAN is an interesting solution to manage parallel versions of multiple SDKs. It’s a tool that’s designed for UNIX-based systems. It offers a convenient CLI and API for installing, switching, removing, and listing SDKs.

Besides JDK, SDKMAN supports tons of SDKs. Check out SDKMAN supported SDKs.

Installing SDKMAN is quite simple. Just run the following command.

$ curl -s "https://get.sdkman.io" | bash

Follow the on-screen instructions to complete the installation. Once finished, restart the terminal and run the following command to load SDKMAN.

$ source "$HOME/.sdkman/bin/sdkman-init.sh"

Verify that SDKMAN is successfully installed.

$ sdk version

The following command will list all the available JDKs that can be installed using SDKMAN.

$ sdk list java

In my case, the following command will install AdoptOpenJDK 11 (LTS).

$ sdk install java 11.0.9.hs-adpt

SDKMAN will ask whether to set it for default. If there’s no other version installed, then SDKMAN will set it as the default.

For more in-depth use of SDKMAN, check out the official SDKMAN usage guide.

Final thoughts

Installing JDK is a must for those interested in working with Java. Follow the method that suits you the best.

New to Java programming? Here’s a quick list of Java tutorials for you to get started.

Happy computing!

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.