How to Install OpenJDK 11 on Fedora 36 Linux

Java is a general-purpose, class-based, object-oriented multipurpose programming language that is popular due to the design of having lesser implementation dependencies, meaning that the compiled Java code can be run on all platforms that support Java without the need for recompilation. Java is also fast, secure, and reliable, therefore. It is widely used for developing Java applications in laptops, data centers, game consoles, scientific supercomputers, cell phones, etc.

The tutorial will look at installing the OpenJDK version instead of the default Oracle JDK. The difference between these two is licensing. OpenJDK is an entirely free, open-source Java with a GNU General Public License, and Oracle JDK requires a commercial license under the Oracle Binary Code License Agreement. Other differences are release schedules and other factors that come into play; however, performance is the same.

In the following tutorial, you will learn how to install OpenJDK 11 LTS, better known as Java 11 LTS, using Fedora 36 default repository. The tutorial will also demonstrate how to switch Java alternative default versions.

Update Fedora Linux

The first step is to make sure your system is up-to-date to avoid issues during the installation and for good practice. This is done by opening your terminal and using the following command.

sudo dnf upgrade --refresh

Install OpenJDK 11 – DNF Method

The first and most recommended option is to install OpenJDK using the default version available from the Fedora appstream. First, search to find what is available.

In your terminal, use the following command.

dnf search java-11-openjdk | grep java-11

Example output:

How to Install OpenJDK 11 on Fedora 36 Linux

As the above output states, OpenJDK 11 is available to install along with additional installation options if required.

The tutorial will show the most commonly used installation commands, and you can further customize your input.

Install OpenJDK 11 LTS

sudo dnf install java-11-openjdk -y

Install OpenJDK 11 LTS – Headless

sudo dnf install java-11-openjdk-headless

Install OpenJDK 11 LTS – DEVEL

sudo dnf install java-11-openjdk-devel

Switching Alternative Java Versions

Once you installed OpenJDK 11, you may notice an alternative version number when checking using the standard java –version command. Alternatively, you may install an alternative version that you would like to switch between. This can be done with the update-alternatives –config java command.

First, check what version is enabled. In the tutorial’s case, OpenJDK 17 was already the default-enabled option.

java --version

Example output:

How to Install OpenJDK 11 on Fedora 36 Linux

Next, list the alternative Java versions as follows.

sudo update-alternatives --config java

Example output:

So as above, you see that Java 17 is enabled in the above example, but say you want to change to Java 11 LTS (OpenJDK 11), you would enter the number 2.

Once done, re-check the default version available using the following command.

java --version

Example output:

To switch back to any other installed versions, use the same process.

Test Java – Create Hello World Application

It is always handy to test installations of these kinds to confirm everything is working correctly after being installed. The easy way is to create a small test using the famous Hello World example.

First, create the Java program file as follows.

sudo nano

Next, add the following Java code to the file below.

public class hello {
  public static void main(String[] args) {
    System.out.println("hi from LinuxCapable!");

Save the file CTRL+O, then exit CTRL+X.

Next, compile the code using the following terminal command javac.


You may still encounter issues compiling, delete the file and use the following instead with the –release 11 <filename>.java.

javac --release 11

Finally, run the Java code with the following command.

java hello

Example output:

How to Install OpenJDK 11 on Fedora 36 Linux

Comments and Conclusion

In this tutorial, you have learned how to install Java 11 LTS on Fedora 36 Linux. You should now be able to run Java applications on your system that require Java 11 or, better yet, compile code.

For developers, ideally, you would like to start looking towards Java 17, which is an LTS version for your application development.


Like to get automatic updates? Follow us on one of our social media accounts!