How to install Java in Fedora?

Java is one of the most popular programming languages. One of the biggest reasons why Java is so popular is because it is a platform-independent language. That means a program written in java can run on several different types of machines. But the only thing is JRE(Java Runtime Environment) should be installed on the computer where you want to run the Java code.

In this article, I will discuss how to install Java in Fedora Linux.

Prerequisites

You should have the root permission to install packages on a Fedora system.

How to install Java in Fedora

Before you run the command to install and configure the Java on your system, check if it is already installed or not by using the given command.

java --version

If java is already installed on your system then it will display its version. If it is not installed you will see nothing or output as given in the image below.

java version

There are different flavors and versions of Java that exist for Linux. You can install a specific type by visiting its official documentation.

Most of the Java applications uses one of the following –

  • OpenJDK – An open-source implementation of the Java Platform, Standard Edition. This version is preferred and included in Fedora.
  • Oracle Java SE — Officially released by Oracle it is a free JDK that is not open-source. You should use it if OpenJDK is not sufficient.

The above two flavors come in different versions for example –

  • Specific version (e.g. 11)
  • Long Term Support or LTS
  • Latest

Installing OpenJDK in Fedora

As discussed above OpenJDK is an open-source implementation of the java development kit. It comes preinstalled in most Linux distributions if it is not in your system then use the following command to install it –

First, check the available version of OpenJDK on a Fedora system –

dnf search openjdk

Next, use the following command to install a specific version of OpenJDK –

sudo dnf install <package-name>

For example –

sudo dnf install java-11-openjdk.x86_64

Install latest OpenJDK in Fedora –

sudo dnf install java-latest-openjdk.x86_64

Next, you can verify the installation by using the given command –

java --version

This will display the installed java version.

java version

Installing Oracle Java SE

To install Oracle Java SE on your Fedora system you need to download the JDK rpm package from its official website.

download java jdk

Once the download is completed you can use the following command to install the Java rpm package on your Fedora system.

sudo dnf install jdk-17_linux-x64_bin.rpm

This will install the Java SE 17 on your system.

Switching between Java versions

If you have installed multiple Java versions then you can switch between them by using the given command.

sudo alternatives --config java

This will display the list of all installed Java versions. Press t and then enter the selection number to set a version default.

You can verify the changes by using –

java --version

Conclusion

I hope you have successfully installed java on your Fedora system. Now if you have a query then write us in the comments below.

Leave a Comment