FedoraRHEL Based

How To Install Java on Fedora 40

Install Java on Fedora 40

In this tutorial, we will show you how to install Java on Fedora 40. Before diving into the installation process, it’s essential to grasp the fundamentals of Java and its components. Java consists of two main parts: the Java Development Kit (JDK) and the Java Runtime Environment (JRE). The JDK is a software development kit that provides the necessary tools and libraries for developing Java applications, while the JRE is responsible for running Java programs on your system.

Java follows a versioning scheme, with Long-Term Support (LTS) versions being the most stable and recommended for production environments. At the time of writing, the latest LTS version is Java 17, which is fully compatible with Fedora 40. However, depending on your specific requirements, you may opt for other versions like Java 8 or Java 11.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Java programming language on Fedora 40.


Before we dive into the installation process, ensure that you have the following prerequisites in place:

  • A server running one of the following operating systems: Fedora 40.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • You will need access to the terminal to execute commands. Fedora provides the Terminal application for this purpose. It can be found in your Applications menu.
  • A stable internet connection to download the necessary packages.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Java on Fedora 40

Step 1. Update the System.

Before proceeding with the installation, it’s recommended to update your Fedora 40 system to the latest packages and security patches. Open the terminal and run the following command:

sudo dnf clean all
sudo dnf update

This command will update your system with the latest available packages, ensuring a smooth and compatible installation process.

Step 2. Installing Java on Fedora 40.

  • Installing OpenJDK

OpenJDK, the open-source implementation of Java, is the preferred choice for many developers due to its compatibility and performance. To install OpenJDK on Fedora 40, follow these steps:

### For OpenJDK 8 ###
sudo dnf install java-1.8.0-openjdk-devel

### For OpenJDK 11 ###
sudo dnf install java-11-openjdk-devel

### For OpenJDK 17 ###
sudo dnf install java-17-openjdk-devel

Once the installation is complete, verify the Java version by running:

java -version
  • Installing Oracle JDK

If you prefer the official Oracle JDK, you can download and install it from the Oracle website.

    1. Visit the Oracle JDK download page.
    2. Accept the license agreement and download the appropriate JDK version for your system (e.g., jdk-11.0.11_linux-x64_bin.tar.gz).
    3. Open the terminal and navigate to the directory where you downloaded the JDK archive.
    4. Extract the archive using the following command:
tar -xvf jdk-11.0.11_linux-x64_bin.tar.gz
    1. Move the extracted JDK directory to /opt:
sudo mv jdk-11.0.11 /opt/
    1. Set up the environment variables by adding the following lines to the /etc/profile file:
export JAVA_HOME=/opt/jdk-11.0.11
export PATH=$PATH:$JAVA_HOME/bin
    1. Save the changes and reload the profile file:
source /etc/profile
    1. Verify the Oracle JDK installation by running:
java -version

Step 3. Configuring Java on Fedora 40.

After installing Java, it’s important to configure your system to recognize and use the installed version correctly. Here’s how to set up the JAVA_HOME and PATH environment variables and select the default Java version using the alternatives command:

sudo nano /etc/profile

Add the following lines at the end of the file, replacing /path/to/java with the actual path to your Java installation:

export JAVA_HOME=/path/to/java
export PATH=$PATH:$JAVA_HOME/bin

Save the changes and exit the text editor, then reload the profile file to apply the changes:

source /etc/profile

Use the alternatives command to select the default Java version:

sudo alternatives --config java

This command will display a list of installed Java versions. Enter the number corresponding to the version you want to set as default.

Verify the Java configuration by running:

java -version
javac -version

The output should display the selected Java version for both the Java runtime and the Java compiler.

Congratulations! You have successfully installed Java. Thanks for using this tutorial for installing the Java programming language on your Fedora 40 system. For additional or useful information, we recommend you check the official Java website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button