How To 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.
Prerequisites
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.
-
- Visit the Oracle JDK download page.
- Accept the license agreement and download the appropriate JDK version for your system (e.g.,
jdk-11.0.11_linux-x64_bin.tar.gz
). - Open the terminal and navigate to the directory where you downloaded the JDK archive.
- Extract the archive using the following command:
tar -xvf jdk-11.0.11_linux-x64_bin.tar.gz
-
- Move the extracted JDK directory to
/opt
:
- Move the extracted JDK directory to
sudo mv jdk-11.0.11 /opt/
-
- 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
-
- Save the changes and reload the profile file:
source /etc/profile
-
- 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.