install Java on Fedora

How to Install Java on Fedora Linux

Java is an essential high-level language for development. So learning how to install Java with DNF or RPM on Fedora Linux machines is essential. It houses Java Development Kit (JDK) and Java Runtime Environment (JRE), Loader, Javac, and Jar for developing Java applications.

There are two Java versions available: OpenJDK and Oracle JDK. Oracle JDK requires a license for commercial use due to its commercial features. On the other hand, OpenJDK is open-source and does not require any permission to use. 

In this guide, we will cover how to install both versions of Java on Fedora. This article will also provide an installation guide on how to install Java Virtual Machine (JVM) and Java Runtime Environment (JRE) as part of the Java Development Kit (JDK). So, let’s get started.

Prerequisites

For this tutorial, you will need an account with sudo privileges on the Fedora system. You’ll also need a DNF installer and access to the terminal. 

Java Components 

The following is a list of components that are usually installed with OpenJDK and Oracle JDK:

  • Java Runtime Environment (JRE): runs Java code and applications
  • Java Virtual Machine (JVM): the main component of the JRE
  • Java Development Kit (JDK): used for development and coding
  • Java Web Start (JavaWS): this component starts applications from the internet
  • JavaFX: this module is used to create a Java desktop application

Install Java on Fedora Linux

This article serves as a guide on how to install Java on the Fedora distribution. It is divided into two sections: Installing OpenJDK and installing OracleJDK. Let’s look at the steps required for Fedora Linux.

Install OpenJDK on Fedora

Update the System

The first step is to update the Fedora system before installing any new package. Update the packages using the DNF package manager. Open the terminal using the shortcut key “Ctrl + Alt + T”. For example:

sudo dnf upgrade

You should get a similar output:

install Java on Fedora

Install the OpenJDK on Fedora

Secondly, install the open JDK on Fedora systems. Before that, check if Java already exists or not. Type the command given below:

java –version

If it is not installed, you will get a similar output as this:

check java version

The process to install OpenJDK is pretty straightforward in Fedora. Simply use the dnf package to install OpenJDK from the Fedora repository.

Input:

sudo dnf install -y java-18-openjdk-devel
sudo dnf install -y java-17-openjdk-devel
sudo dnf install -y java-11-openjdk-devel

You should get a similar output:

install Java on Fedora 1

For Java applications, you need JDK along with JRE to run some specific Java-based software and applications. Therefore install OpenJDK JRE using the same command. For instance, type: 

sudo dnf install -y java-18-openjdk
sudo dnf install -y java-17-openjdk
sudo dnf install -y java-11-openjdk

The output should look something like this:

install JDK

After the successful installation, verify the Java version. For this step, type the command given below:

javac –version

You should get a similar output:

install JRE

Install Oracle Java on Fedora

Before installing Oracle Java JDK, check the system configurations from the website. You must have Fedora distribution with 64-bit based architecture. Furthermore, the system should have enough space to install this Java version. 

Alternatively, you can also install Oracle JDK for commercial use. The process is the same as the installation of OpenJDK. First, install the JDK and then JRE for Oracle Java, and the wget package. Through this, you can fetch the package through the URL. Type:

sudo dnf install -y wget

Secondly, get the package using the wget command. For example:

sudo wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

After the package has been downloaded, install it using the rpm command. Specifically, type:

sudo rpm -ivh jdk-18_linux-x64_bin.rpm

The output should look something like this:

install java on fedora

Oracle JDK installs Java in /usr/java/ directory. On the other hand, if you want to change the directory, you can add the path in the –prefix option. For example:

rpm -ivh –prefix=/<path>/ rpmfile 

After the successful installation, verify the Java version. For this step, type the command given below:

javac –version

The output should look something like this:

install java on fedora

Set Default Java Version on Fedora

Let’s assume you have three Java versions installed on your Fedora system. You can assign which version to use as default. For instance, type:

sudo update-alternatives --config java

You should get similar output as this:

install java on fedora

From the list, choose the one that you want to set as default. For this, just press the number given in the list besides each Java version.

Set JAVA_HOME Variable

The next step is to add JAVA_HOME to the environment variable. Setting the variable will allow you to find the required Java utilities and programs. Also, programs written in Java utilize this variable to determine what locally installed version of Java it is going to use. For this step, edit the /etc/environment file. Open this file using your favorite editor.

For example:

sudo nano /etc/environment

Next, add the following lines in the file:

/etc/environment
JAVA_HOME="/usr/lib/jvm/java-18-openjdk-amd64/"

Press “Ctrl + S” to save the changes. After that, press “Ctrl + X” to exit from the editor. 

Lastly, verify the JAVA_HOME environment variable using the echo command. For example: 

echo $JAVA_HOME

Integrated Development Environment (IDE) for Java

Now that you have installed Java successfully, you can use the following IDEs to create Java desktop, web, and mobile applications:

  • NetBeans
  • Eclipse
  • IntelliJ IDEA

And that’s it for this installation guide. You can now successfully install different Java versions in your Fedora Linux system. We hope you were able to learn something new and helpful today. For more information on Java, check its official documentation.

You can check out some of the installation guides available on this site, such as how to install Python, OnlyOffice 9, or even Bottles if you want to explore your Linux distro. 

If this guide helped you, please share it.

Leave a Reply
Related Posts