FedoraRHEL Based

How To Install Apache Maven on Fedora 40

Install Apache Maven on Fedora 40

In this tutorial, we will show you how to install Apache Maven on Fedora 40. Apache Maven is a powerful project management and comprehension tool designed specifically for Java projects. It plays a crucial role in managing builds, documentation, and dependencies, streamlining the development process, and ensuring consistent and efficient project execution. In this article, we will guide you through the step-by-step process of installing Apache Maven on Fedora 40, a popular Linux distribution known for its stability, security, and user-friendly environment.

Fedora 40 provides an ideal platform for installing Apache Maven, thanks to its robust package management system and compatibility with Java development tools. By following the instructions outlined in this guide, you’ll be able to set up Maven on your Fedora 40 system and take advantage of its extensive features to enhance your Java development workflow.

Prerequisites

System Requirements

Before proceeding with the installation of Apache Maven, ensure that you have Fedora 40 installed on your system. Additionally, you’ll need access to the terminal or command line with sudo privileges to execute the necessary commands throughout the installation process.

Java Development Kit (JDK)

Apache Maven relies on the Java Development Kit (JDK) to function properly. Therefore, it’s essential to have JDK installed on your Fedora 40 system before installing Maven. To check if JDK is already installed, open the terminal and run the following command:

java -version

If JDK is installed, the command will display the Java version information. If JDK is not installed or if you need to install a specific version, proceed to Step 2 of this guide.

Step 1: Update the System

Before installing any new software, it’s always recommended to update your Fedora system to ensure you have the latest packages and security patches. Updating the system helps maintain compatibility and stability during the installation process. To update your Fedora 40 system, open the terminal and run the following command:

sudo dnf update

This command will retrieve the latest package information and prompt you to confirm the installation of any available updates. Press “Y” and hit Enter to proceed with the update process. Once the update is complete, your Fedora 40 system will be up to date and ready for the next steps.

Step 2: Install Java JDK

Installing OpenJDK

Apache Maven requires the Java Development Kit (JDK) to be installed on your system. OpenJDK, an open-source implementation of the Java platform, is widely used and recommended for Maven. To install OpenJDK on Fedora 40, use the following command in the terminal:

sudo dnf install java-11-openjdk-devel

This command will install the OpenJDK 11 development package, which includes the necessary tools and libraries for Java development.

Verification of Java Installation

After the installation is complete, verify that Java is properly installed by running the following command:

java -version

If the installation was successful, you should see the Java version information displayed in the terminal output.

Step 3: Download Apache Maven

Finding the Latest Version

To download Apache Maven, visit the official Apache Maven website. On the download page, you’ll find the latest stable version of Maven available for download. At the time of writing, the latest version is 3.9.6, but make sure to check for any newer versions.

Downloading Maven

Once you have identified the latest version of Maven, use the wget command in the terminal to download the Maven binary archive. Replace the URL in the following command with the appropriate link for the version you want to download:

https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gzwget 

This command will download the Maven binary archive (apache-maven-3.9.9-bin.tar.gz) to your current directory.

Step 4: Extract and Install Maven

Extracting the Downloaded Archive

After downloading the Maven binary archive, you need to extract its contents. Use the following tar command to extract the archive:

sudo tar xzf apache-maven-3.9.9-bin.tar.gz -C /opt

This command will extract the contents of the archive to the /opt directory, which is a common location for installing optional software packages.

Moving Files to Appropriate Directory

After extracting the archive, you’ll find a directory named apache-maven-3.9.9 inside the /opt directory. To simplify the Maven installation path, rename this directory to maven using the following command:

sudo mv /opt/apache-maven-3.9.9 /opt/maven

This command will move the extracted Maven files to the /opt/maven directory, making it easier to reference and configure Maven in the subsequent steps.

Step 5: Configure Environment Variables

Setting Up Environment Variables

To make Maven accessible from anywhere in the terminal and ensure its proper functioning, you need to set up environment variables. Environment variables provide a way to define the location of Maven and include it in the system’s PATH.

Creating Environment Variable File

Create a new file named maven.sh in the /etc/profile.d/ directory to store the Maven environment variables. Open the file using a text editor with sudo privileges:

sudo nano /etc/profile.d/maven.sh

Inside the file, add the following lines:

export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

These lines set the M2_HOME variable to the Maven installation directory (/opt/maven) and add the Maven bin directory to the system’s PATH variable, allowing you to run Maven commands from anywhere in the terminal.

Save the file and exit the text editor.

Making Script Executable and Loading Variables

To make the maven.sh script executable and load the environment variables into the current shell session, run the following commands:

sudo chmod +x /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh

The first command grants execute permissions to the maven.sh script, allowing it to be run as an executable file. The second command, source, loads the environment variables defined in the script into the current shell session, making them immediately available for use.

Step 6: Verify Installation

Verification Process

To verify that Apache Maven is installed correctly and the environment variables are properly set up, run the following command in the terminal:

mvn -version

This command will display the Maven version information, along with the Java version and operating system details.

Expected Output

If the installation is successful, you should see an output similar to the following:

Apache Maven 3.9.9 (c35e1c03d56f; 2024-05-23T16:56:35+05:30)
Maven home: /opt/maven
Java version: 11.0.18, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-2.fc40.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.2.16-200.fc40.x86_64", arch: "amd64", family: "unix"

This output confirms that Maven is installed correctly and provides information about the Maven version, Java version, and operating system details.

Congratulations! You have successfully installed Maven. Thanks for using this tutorial for installing Apache Maven on Fedora 40. system. For additional help or useful information, we recommend you check the Apache 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

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