FedoraRHEL Based

How To Install Apache Maven on Fedora 43

Install Apache Maven on Fedora 43

Apache Maven stands as one of the most powerful build automation and project management tools in the Java ecosystem. Whether you’re developing enterprise applications, microservices, or simple Java programs, Maven streamlines dependency management and standardizes your project structure. Fedora 43 brings exciting changes for Java developers, including Maven 4 as the default version—a major release after 15 years of Maven 3 dominance.

This comprehensive guide walks through two proven installation methods: the DNF package manager approach and manual installation from the official Apache website. By the end, you’ll have a fully functional Maven environment ready for Java development. The entire process takes approximately 15-20 minutes, and both beginners and experienced system administrators will find these instructions straightforward to follow.

What is Apache Maven?

Apache Maven revolutionizes how developers manage Java projects. At its core, Maven uses a Project Object Model (POM) defined in XML files to describe project structure, dependencies, and build configurations. This approach eliminates much of the manual configuration traditionally required in Java development.

Maven excels at dependency management. Instead of manually downloading JAR files and managing classpaths, developers simply declare dependencies in the pom.xml file. Maven automatically downloads required libraries from central repositories and resolves transitive dependencies. This automation saves countless hours and reduces configuration errors significantly.

The tool follows the “convention over configuration” philosophy. Standard directory layouts mean developers spend less time configuring build paths. Maven also integrates seamlessly with continuous integration systems like Jenkins, GitLab CI, and GitHub Actions. Its plugin architecture extends functionality for testing, code analysis, deployment, and documentation generation.

Prerequisites

Before installing Apache Maven on Fedora 43, ensure your system meets these requirements. A working Fedora 43 installation—either desktop or server edition—serves as the foundation. You’ll need terminal access and familiarity with basic Linux commands.

Administrative privileges are essential for system-wide installation. Either root access or sudo capabilities allow package installation and system configuration. Network connectivity enables downloading packages from Fedora repositories and Maven dependencies from Apache servers.

Hardware requirements remain modest. A minimum of 2GB RAM ensures smooth operation, though 4GB or more improves build performance for larger projects. Reserve at least 10GB of free disk space for Maven, Java, and downloaded dependencies. Finally, basic knowledge of text editors like nano or vim helps when modifying configuration files.

Step 1: Update Your Fedora System

Starting with a fully updated system prevents compatibility issues and ensures access to the latest security patches. Open your terminal application and execute the system update command.

sudo dnf upgrade --refresh

This command refreshes repository metadata and upgrades all installed packages to their latest versions. The process may take several minutes depending on the number of pending updates and your internet connection speed. Accept any prompts to proceed with the upgrade.

If kernel updates were applied during this process, consider rebooting your system. A fresh restart ensures all updated components load properly. After rebooting, verify your system is current by running the upgrade command again—it should report no packages need updating.

Step 2: Install Java Development Kit (JDK)

Maven requires a Java Development Kit to function because Maven itself is written in Java. Fedora 43 offers several OpenJDK versions through its repositories, including OpenJDK 11, 17, 21, and 25. Each version receives ongoing updates and security patches.

For most development scenarios, OpenJDK 21 provides an excellent balance of modern features and long-term support. Install it with:

sudo dnf install java-21-openjdk-devel

The devel package includes the Java compiler (javac) and development tools necessary for Maven and Java development. The standard java-21-openjdk package only provides the runtime environment, which is insufficient for building projects.

After installation completes, verify Java is properly configured:

java -version
javac -version

Both commands should display version information confirming OpenJDK 21 installation. The output includes the version number, build information, and runtime environment details.

Fedora 43 no longer sets a default system-wide JDK automatically. If you have multiple Java versions installed, manage them with the alternatives system:

sudo alternatives --config java

This interactive command displays available Java installations and allows selection of the default version. Choose the appropriate version for your development needs.

Method 1: Install Apache Maven via DNF (Recommended)

The DNF package manager offers the simplest and most maintainable installation method for most users. Fedora’s AppStream repository provides Maven packages that integrate smoothly with the operating system.

Benefits of DNF Installation

Using DNF for Maven installation brings several advantages. Automatic dependency resolution ensures all required components install correctly. Future updates arrive through the standard system update process, keeping Maven current with security patches and bug fixes. System integration means Maven works immediately after installation without manual configuration.

Fedora 43 specifically ships Maven 4 as the default version—representing a significant upgrade from Maven 3. This new major release includes performance improvements, better error messages, and enhanced dependency resolution algorithms.

Installation Command

Execute a single command to install Maven:

sudo dnf install maven

DNF downloads Maven binaries, required dependencies, and manual pages. Accept the installation prompt, and the package manager handles everything automatically. The download size typically ranges from 50-100 MB depending on already-installed dependencies.

Verify DNF Installation

Confirm successful installation by checking the Maven version:

mvn -version

The output displays comprehensive information:

Apache Maven 4.0.0
Maven home: /usr/share/maven
Java version: 21.0.x, vendor: Red Hat, Inc.
Java home: /usr/lib/jvm/java-21-openjdk
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.x.x", arch: "amd64", family: "unix"

This output confirms Maven version, installation directory, Java configuration, and system information. If you see “command not found,” log out and log back in to refresh your shell environment, or run source /etc/profile.

Method 2: Manual Installation from Apache Website

Manual installation provides complete control over Maven versions and installation locations. This method suits developers who need specific Maven versions or want to run multiple versions simultaneously.

When to Choose Manual Installation

Several scenarios favor manual installation. Projects requiring specific Maven versions benefit from this approach. Testing applications against different Maven releases becomes straightforward. Organizations with strict version control policies often prefer manually managed installations.

Download Maven Binary

Navigate to a suitable directory and download the latest Maven release from Apache’s official servers:

cd /tmp
wget https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz

For enhanced security, verify the download integrity using the SHA-512 checksum:

wget https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz.sha512
sha512sum -c apache-maven-3.9.11-bin.tar.gz.sha512

A successful verification displays “OK” confirming the archive is intact and authentic.

Extract and Install Maven

Extract the downloaded archive:

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

Move the extracted directory to /opt, the standard location for third-party software on Linux systems:

sudo mkdir -p /opt
sudo mv apache-maven-3.9.11 /opt/maven

Set appropriate ownership for system-wide access:

sudo chown -R root:root /opt/maven

Configure Environment Variables

Maven requires environment variables to function correctly from any directory. Create a dedicated configuration script:

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

Add the following configuration:

#!/bin/bash
export M2_HOME=/opt/maven
export MAVEN_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}

The M2_HOME and MAVEN_HOME variables point to the Maven installation directory. The PATH modification ensures the mvn command is accessible system-wide.

Save the file and make it executable:

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

Load the new environment variables in your current session:

source /etc/profile.d/maven.sh

This configuration persists across reboots and applies to all users. For user-specific installation, add these exports to ~/.bashrc instead.

Step 3: Verify Maven Installation

Thorough verification confirms Maven operates correctly. Run the version command:

mvn -version

Examine the output carefully. The Maven version should match what you installed. The Java version and Java home path confirm proper JDK detection. The Maven home directory shows where Maven binaries reside.

Additional verification commands provide deeper insight:

which mvn
echo $M2_HOME
echo $PATH | grep -i maven

The which command reveals the executable location. Environment variable checks confirm proper configuration. All three commands should return valid paths without errors.

Step 4: Configure Maven Settings (Optional)

Maven supports extensive customization through settings files. Two configuration levels exist: global settings affecting all users and user-specific settings.

Global settings reside at /opt/maven/conf/settings.xml for manual installations or /etc/maven/settings.xml for DNF installations. User-specific settings belong in ~/.m2/settings.xml and override global configurations.

Create a user settings file for personal customization:

mkdir -p ~/.m2
nano ~/.m2/settings.xml

Common Configurations

Custom Local Repository Location:

<settings>
  <localRepository>/home/username/maven-repo</localRepository>
</settings>

Proxy Configuration for Corporate Networks:

<settings>
  <proxies>
    <proxy>
      <id>corporate-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.company.com</host>
      <port>8080</port>
    </proxy>
  </proxies>
</settings>

These settings help Maven function correctly in various network environments and accommodate organizational requirements.

Step 5: Create and Test a Maven Project

Validating your installation with a real project confirms everything works correctly. Maven’s archetype system generates project skeletons instantly.

Generate a Sample Project

Create a dedicated directory for Maven projects:

mkdir -p ~/maven-projects
cd ~/maven-projects

Generate a simple Java application using the quickstart archetype:

mvn archetype:generate -DgroupId=com.example.app -DartifactId=test-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

This command creates a complete project structure with source directories, test directories, and a configured pom.xml file. The parameters define your project’s group identifier, artifact name, and archetype template.

Build the Project

Navigate into the newly created project directory:

cd test-app

Execute the Maven build lifecycle:

mvn package

Maven downloads required plugins and dependencies on first run. The build process compiles source code, runs unit tests, and packages the application into a JAR file. A successful build displays “BUILD SUCCESS” with timing information.

Run the Application

Execute the compiled application:

java -cp target/test-app-1.0-SNAPSHOT.jar com.example.app.App

The output should display “Hello World!” confirming successful compilation and execution. Your Maven installation is fully operational and ready for development work.

Understanding Maven Project Structure

Maven enforces a standardized directory layout that promotes consistency across projects. Understanding this structure accelerates development and simplifies collaboration.

Directory Purpose
src/main/java Application source code
src/main/resources Configuration files and resources
src/test/java Unit test source code
src/test/resources Test configuration files
target Compiled classes and build artifacts
pom.xml Project Object Model configuration

The pom.xml file serves as the project’s heart. It defines dependencies, plugins, build configurations, and project metadata. Maven reads this file to understand how to build, test, and package your application.

Common Maven Commands Reference

Familiarity with essential Maven commands accelerates development workflows. These commands cover most daily development tasks:

  • mvn clean — Removes the target directory, eliminating previous build artifacts
  • mvn compile — Compiles source code into bytecode
  • mvn test — Executes unit tests using configured testing frameworks
  • mvn package — Creates distributable JAR or WAR files
  • mvn install — Installs the artifact to your local repository for use by other projects
  • mvn dependency:tree — Displays the complete dependency hierarchy
  • mvn clean install — Combines cleaning and installation in one command

The -DskipTests flag bypasses test execution when quick builds are needed. The -X flag enables debug output for troubleshooting complex issues.

Troubleshooting Common Issues

Even straightforward installations occasionally encounter problems. These solutions address the most frequent issues.

Command Not Found Error

If the terminal reports “mvn: command not found,” the PATH environment variable likely needs attention. First, verify the installation exists:

ls -la /opt/maven/bin/mvn

If the file exists, reload environment variables:

source /etc/profile.d/maven.sh

For persistent issues, log out completely and log back in. This refreshes the entire shell environment.

Java Version Conflicts

Maven requires compatible Java versions. Error messages mentioning unsupported class file versions indicate Java mismatches. Check current Java configuration:

java -version
update-alternatives --display java

Switch to a compatible Java version using the alternatives system:

sudo alternatives --config java

For manual installations, explicitly set JAVA_HOME in the maven.sh configuration file.

Permission Denied Errors

Permission errors during installation typically stem from incorrect file ownership. Fix ownership recursively:

sudo chown -R root:root /opt/maven
sudo chmod -R 755 /opt/maven

User-specific installations in home directories should be owned by the respective user account.

Network and Repository Issues

Maven downloads dependencies from remote repositories. Connection timeouts suggest network problems or corporate firewall restrictions. Configure proxy settings in ~/.m2/settings.xml if behind a corporate proxy. Consider using mirror repositories closer to your geographic location for improved download speeds.

Congratulations! You have successfully installed Maven. Thanks for using this tutorial for installing Apache Maven on Fedora 43 Linux 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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button