How to Install Apache Maven on Fedora 40 or 39

Apache Maven is a pivotal tool in modern software development, particularly for Java projects. Its design philosophy centers around simplifying project management and enhancing build automation.

Let’s highlight some of its key features:

  • Effortless Project Setup: Maven streamlines the initiation of new projects or modules, adhering to best practices and ensuring rapid setup.
  • Consistency Across Projects: It offers a uniform approach for all projects, significantly reducing the learning curve for new developers.
  • Advanced Dependency Management: Maven excels in managing dependencies, including automatic updates and handling transitive dependencies.
  • Simultaneous Multi-project Handling: The tool is adept at managing multiple projects concurrently, enhancing productivity.
  • Extensive Libraries and Metadata Repository: Maven provides immediate access to a vast repository of libraries and metadata, often updated in real-time with major Open-Source projects.
  • Customizable and Extensible: Users can easily create plugins in Java or scripting languages, tailoring Maven to their needs.
  • Minimal Configuration for New Features: Access new functionalities with little to no additional configuration.
  • Integration with Ant Tasks: Maven integrates with Ant tasks for dependency management and deployment outside its ecosystem.
  • Model-Based Builds Without Scripting: This technique utilizes metadata to build projects into predefined outputs like JARs or WARs, eliminating the need for scripting.
  • Automated Documentation and Reporting: Maven can generate websites or PDFs for project documentation and reports, utilizing the same metadata as the build process.
  • Streamlined Release Management: It integrates with source control systems for efficient release management and can publish distributions for external project use.
  • Centralized Dependency Repository: Promotes a central repository for JARs and dependencies, facilitating reuse and backward compatibility.

Next, we’ll walk you through the step-by-step process of installing Apache Maven and offer two distinct installation methods.

Update Fedora Before Apache Maven Installation

Ensuring System Up-to-Date

Before installing Apache Maven, updating and upgrading your Fedora system is crucial. This step ensures that all packages are current, reducing potential conflicts during the Maven installation. Execute the following command in the terminal to refresh your system’s package index and upgrade the packages:

sudo dnf upgrade --refresh

This command combines two actions: upgrade updates all installed packages to their latest versions, and --refresh forces a refresh of the repository metadata. It’s important to regularly perform this step to maintain system stability and security.

Method 1: Install Apache Maven via Appstream (Default Method)

Initiating Installation Using Fedora’s Default Repository

Installing Apache Maven on Fedora is straightforward with the Fedora Appstream, the operating system’s default repository. This repository typically contains a stable version of Maven, updated biannually to include major version upgrades. This ensures a balance between up-to-date features and system stability.

To install Apache Maven, run the following command in the terminal with root access:

sudo dnf install maven

This command retrieves and installs the latest version of Maven available in Fedora’s default repository. The dnf package manager handles dependencies and version compatibility, streamlining the installation process.

Verifying Maven Installation

Post-installation, it’s essential to verify the successful installation of Apache Maven. This step confirms that Maven is correctly installed and operational. In the terminal, execute the following command:

mvn -version

This command displays the installed version of Apache Maven. A successful installation will output the version details, confirming that Maven is ready.

Method 2: Install Apache Maven on Fedora via Tarball (Latest Version)

Preparing Java Installation

Before installing Apache Maven, ensure Java is installed on your Fedora system. Java is a prerequisite for Maven. Install Java OpenJDK by executing the following command:

sudo dnf install java-openjdk

This command installs the Java OpenJDK package, which Maven requires to function.

Downloading Apache Maven

To download the latest version of Apache Maven, first visit the official Apache Maven website to identify the most recent release. Then, use the wget command to download the specified Maven version.

For instance, to download Maven 3.9.6, execute:

wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz

This command fetches the specified Apache Maven binary archive and saves it to your local machine.

Extracting and Installing Maven

After downloading, navigate to the directory containing the downloaded file. Extract the contents of the archive using:

tar xzf apache-maven-3.9.6-bin.tar.gz

This command creates a new directory named “apache-maven-3.9.6” containing the extracted files.

Configuring Environment Variables

Temporary Environment Configuration

For one-time use, set the Maven environment variables manually in the terminal:

export M2_HOME=/path/to/maven
export PATH=$PATH:$M2_HOME/bin

Replace /path/to/maven with the actual path to your extracted Maven directory.

For example:

export M2_HOME=/home/$USER/apache-maven-3.9.6
export PATH=$PATH:$M2_HOME/bin

Replace /path/to/maven with the path to your Maven directory, like /home/$USER/apache-maven-3.9.6.

Permanent Environment Configuration

To permanently add Maven to your environment, append the export commands to your .bashrc file:

echo export M2_HOME=/home/$USER/apache-maven-3.9.6 >> ~/.bashrc
echo export PATH=$PATH:$M2_HOME/bin >> ~/.bashrc

Important Reminder: It’s crucial to enter these commands in the above sequence. Reversing the order or mixing them up can lead to problems when attempting to use the mvn command. Correct ordering ensures that your environment variables are set up properly for Maven.

After appending these lines, apply the changes by sourcing the .bashrc file:

source ~/.bashrc

This command updates your session, adding the Maven binaries to your system path.

Verifying Maven Installation

To confirm the successful installation of Maven, check its version with:

mvn -version

This command displays the installed Maven version and its configuration. If the installation is successful, you will see the version details, confirming Maven is ready for use.

Create a Test Apache Maven Project

Setting Up a New Maven Project

After installing Apache Maven on your Fedora Linux system, validate the installation by creating a test Maven project. Start by creating a new directory for the project and navigating to it in the terminal.

To generate a new Maven project, run:

mvn archetype:generate -DgroupId=com.example -DartifactId=my-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This command sets up a new Maven project with com.example as the group ID and my-project as the artifact ID using the maven-archetype-quickstart archetype. The -DinteractiveMode=false option instructs Maven to skip additional input requests during project creation.

Conclusion

In this guide, we covered the essentials of installing Apache Maven on Fedora 40 or 39 Linux, covering both the default Appstream method and the manual installation for the latest version. We also touched on verifying and testing your Maven setup by creating a simple project. Remember, keeping your system updated and understanding the basics of Maven’s project structure is key to a smooth experience with Maven.

Useful and Relevant Links

Here are some valuable links related to using Apache Maven:

  • Maven Official Website: Visit the official Apache Maven website for information about the build automation tool, its features, and download options.
  • Maven Features: Explore the various features of Apache Maven to understand its capabilities and tools.
  • Maven History: Learn about the history and development of Apache Maven.
  • Maven Plugins: Access the list of available Maven plugins to extend the functionality of your build process.
  • Maven Extensions: Discover Maven extensions and how to use them to customize and enhance your Maven projects.
  • Maven in Five Minutes: Get started quickly with Apache Maven by following this concise guide.
  • Maven Getting Help: Find various support resources for getting help with Apache Maven, including mailing lists and user groups.
Joshua James
Follow me
Latest posts by Joshua James (see all)