Apache Maven is a build automation and project management tool that simplifies Java development workflows. It handles dependency management, project compilation, testing, and packaging through a standardized project structure and a central repository system. Common use cases include building Spring Boot applications, managing multi-module enterprise projects, and automating CI/CD build pipelines. Maven integrates well with version control systems like Git on Fedora and containerization tools like Docker on Fedora.
This guide covers two installation methods for Fedora: using the DNF package manager for a quick, integrated setup, or downloading the official tarball for precise version control. By the end, you will have a working Maven installation, verified through a test project, with optional automation for future updates.
Choose Your Apache Maven Installation Method
Before starting, decide which installation approach fits your needs. Both methods provide fully functional Maven installations, but they differ in version control and update management.
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| DNF Package Manager | Fedora Repos | Distribution default | Automatic via dnf upgrade | Most users who prefer system-integrated packages |
| Official Tarball | Apache Downloads | Latest stable | Manual or scripted | Developers needing the newest features immediately |
For most users, the DNF method is recommended because it integrates with your system’s package management, receives security updates automatically, and requires no manual configuration. Choose the tarball method only if you need a specific Maven version or require immediate access to the latest release.
Update Fedora Before Apache Maven Installation
First, update your system to ensure all packages are current before installing any new software. This step reduces potential dependency conflicts and also ensures you have the latest security patches.
sudo dnf upgrade --refresh
The --refresh flag forces DNF to synchronize repository metadata before checking for updates. This ensures you see the most recent package versions available.
Method 1: Install Apache Maven with DNF
Fedora’s default repositories already include Apache Maven, making installation straightforward. As a result, DNF handles all dependencies automatically, including the required Java runtime.
Install Maven Package
To begin, run the following command to install Maven and its dependencies:
sudo dnf install maven
DNF installs Maven along with a compatible Java Development Kit (JDK). Additionally, the package manager selects an appropriate OpenJDK version automatically based on Fedora’s current defaults.
Verify Maven Installation
Once installation completes, confirm Maven is accessible and functioning correctly:
mvn -version
The expected output below confirms the installed version, Java runtime, and system details:
Apache Maven 3.9.11 (Red Hat 3.9.11-5) Maven home: /usr/share/maven Java version: 25.0.1, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-25-openjdk Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "6.x.x", arch: "amd64", family: "unix"
With Maven successfully installed via DNF, you can proceed to create a test project to validate your setup, or continue reading to learn the tarball installation method.
Method 2: Install Apache Maven via Official Tarball
Alternatively, the tarball method gives you direct control over which Maven version to install. This approach is particularly useful when you need the latest release before it reaches Fedora’s repositories, or when your project requires a specific Maven version.
Install Java Development Kit
Maven requires a Java Development Kit (JDK) to function. If you installed Maven via DNF previously, Java is already present. For a fresh tarball installation, install OpenJDK first:
sudo dnf install java-21-openjdk-devel
This installs OpenJDK 21, a long-term support (LTS) release suitable for most Maven projects. Next, verify Java is available:
java -version
openjdk version "21.0.x" 2025-xx-xx OpenJDK Runtime Environment (Red_Hat-21.0.x.x.x-x) (build 21.0.x+x) OpenJDK 64-Bit Server VM (Red_Hat-21.0.x.x.x-x) (build 21.0.x+x, mixed mode, sharing)
Download Apache Maven with Automatic Version Detection
Rather than hardcoding version numbers that become outdated, use the GitHub API to detect and download the latest stable Maven 3.x release automatically:
cd /tmp
MAVEN_VERSION=$(curl -s https://api.github.com/repos/apache/maven/tags | grep -oP '"name": "maven-3\.\d+\.\d+"' | head -1 | grep -oP '\d+\.\d+\.\d+')
echo "Downloading Maven $MAVEN_VERSION"
wget https://dlcdn.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz
This command sequence performs four actions:
- Queries the Apache Maven GitHub repository for available tags
- Extracts the latest stable 3.x version number (avoiding 4.x release candidates)
- Stores the version in a variable for consistent use across commands
- Downloads the official binary archive from Apache’s CDN
If you prefer to download a specific version manually, visit the Apache Maven download page and replace
$MAVEN_VERSIONwith your desired version number in subsequent commands.
Extract and Install Maven
Now, extract the downloaded archive to a system-wide location. The /opt directory is conventional for manually installed software:
sudo tar xzf apache-maven-$MAVEN_VERSION-bin.tar.gz -C /opt
sudo ln -sfn /opt/apache-maven-$MAVEN_VERSION /opt/maven
The symbolic link at /opt/maven points to the current version. Consequently, when you upgrade Maven later, updating this symlink switches versions without modifying your PATH configuration.
Configure Environment Variables
Maven requires two environment variables: M2_HOME pointing to the installation directory, and an updated PATH to make the mvn command available system-wide. Therefore, create a profile script that loads these variables for all users:
sudo tee /etc/profile.d/maven.sh <<'EOF'
export M2_HOME=/opt/maven
export PATH=$PATH:$M2_HOME/bin
EOF
This creates a shell script that runs automatically when users log in. To apply the changes immediately without logging out, source the script:
source /etc/profile.d/maven.sh
Alternatively, open a new terminal window for the changes to take effect automatically.
Verify Tarball Installation
Finally, confirm Maven is correctly installed and accessible:
mvn -version
Expected output shows the manually installed version:
Apache Maven 3.9.12 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /opt/maven Java version: 21.0.x, vendor: Red Hat, Inc., runtime: /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"
Create a Test Apache Maven Project
To validate your Maven installation, generate a sample project. This step confirms that Maven can download dependencies, compile code, and execute plugins correctly.
cd ~
mvn archetype:generate -DgroupId=com.example -DartifactId=my-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command creates a new Maven project with the following structure:
-DgroupId=com.examplesets the project’s namespace (typically your organization’s domain reversed)-DartifactId=my-projectnames the project directory and output artifact-DarchetypeArtifactId=maven-archetype-quickstartuses a basic project template-DinteractiveMode=falseskips manual input prompts
After Maven downloads required plugins and dependencies, you should see:
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: X.XXX s [INFO] Finished at: 2025-XX-XXTXX:XX:XX+XX:XX [INFO] ------------------------------------------------------------------------
As a result, the generated my-project directory contains a standard Maven structure with pom.xml, source files in src/main/java, and test files in src/test/java.
Update Maven Tarball Installation
If you installed Maven via DNF, updates arrive automatically through sudo dnf upgrade. However, for tarball installations, use the following script to check for and install newer versions.
Manual Update Command
When an update is needed, run these commands to update your tarball installation to the latest version:
cd /tmp
MAVEN_VERSION=$(curl -s https://api.github.com/repos/apache/maven/tags | grep -oP '"name": "maven-3\.\d+\.\d+"' | head -1 | grep -oP '\d+\.\d+\.\d+')
CURRENT_VERSION=$(mvn -version 2>/dev/null | grep -oP 'Apache Maven \K[0-9.]+' || echo "none")
echo "Current: $CURRENT_VERSION | Latest: $MAVEN_VERSION"
if [ "$CURRENT_VERSION" != "$MAVEN_VERSION" ]; then
wget -q https://dlcdn.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz
sudo tar xzf apache-maven-$MAVEN_VERSION-bin.tar.gz -C /opt
sudo ln -sfn /opt/apache-maven-$MAVEN_VERSION /opt/maven
echo "Updated to Maven $MAVEN_VERSION"
mvn -version
else
echo "Already up to date."
fi
Reusable Update Script
For convenience, save the update logic as a script you can run whenever needed:
sudo tee /usr/local/bin/update-maven.sh <<'EOF'
#!/bin/bash
set -e
# Fetch latest stable Maven 3.x version from GitHub API
MAVEN_VERSION=$(curl -s https://api.github.com/repos/apache/maven/tags | grep -oP '"name": "maven-3\.\d+\.\d+"' | head -1 | grep -oP '\d+\.\d+\.\d+')
CURRENT_VERSION=$(mvn -version 2>/dev/null | grep -oP 'Apache Maven \K[0-9.]+' || echo "none")
echo "Current Maven version: $CURRENT_VERSION"
echo "Latest Maven version: $MAVEN_VERSION"
if [ "$CURRENT_VERSION" = "$MAVEN_VERSION" ]; then
echo "Maven is already up to date."
exit 0
fi
echo "Downloading Maven $MAVEN_VERSION..."
cd /tmp
wget -q "https://dlcdn.apache.org/maven/maven-3/$MAVEN_VERSION/binaries/apache-maven-$MAVEN_VERSION-bin.tar.gz"
echo "Installing to /opt..."
tar xzf "apache-maven-$MAVEN_VERSION-bin.tar.gz" -C /opt
ln -sfn "/opt/apache-maven-$MAVEN_VERSION" /opt/maven
# Cleanup
rm -f "apache-maven-$MAVEN_VERSION-bin.tar.gz"
echo "Updated successfully. New version:"
source /etc/profile.d/maven.sh
mvn -version
EOF
sudo chmod +x /usr/local/bin/update-maven.sh
Then, run the script manually whenever you want to check for updates:
sudo /usr/local/bin/update-maven.sh
Do not automate this script with cron. Unattended Maven upgrades could break ongoing builds or introduce incompatibilities with your projects. Run the update script manually after reviewing the Maven release notes to ensure the new version is compatible with your workflow.
Troubleshoot Apache Maven Issues
Maven Command Not Found
If running mvn returns “command not found” after a tarball installation, the PATH configuration is not loaded. Verify the environment script exists:
cat /etc/profile.d/maven.sh
If the file exists, then source it manually or open a new terminal:
source /etc/profile.d/maven.sh
mvn -version
Otherwise, if the file is missing, recreate it by following the Configure Environment Variables section above.
JAVA_HOME Not Set Error
Some Maven plugins require the JAVA_HOME environment variable. If you encounter errors mentioning JAVA_HOME, add it to your environment:
echo 'export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))' | sudo tee -a /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh
echo $JAVA_HOME
Expected output shows the Java installation path:
/usr/lib/jvm/java-21-openjdk
Dependency Download Failures
If Maven cannot download dependencies, check your network connectivity and proxy settings. For corporate networks requiring a proxy, configure Maven’s settings file:
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<'EOF'
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxy.example.com</host>
<port>8080</port>
</proxy>
</proxies>
</settings>
EOF
Be sure to replace the proxy host and port with your organization’s actual values.
Remove Apache Maven from Fedora
If you no longer need Maven, remove it using the appropriate method for your installation type.
Remove DNF Installation
For Maven installed via DNF, remove the package and clean up unused dependencies:
sudo dnf remove maven
sudo dnf autoremove
In addition, the autoremove command removes packages that were installed as dependencies but are no longer needed by any installed software.
Remove Tarball Installation
For tarball installations, remove the installation directory, symlink, environment script, and update script:
sudo rm -rf /opt/apache-maven-*
sudo rm -f /opt/maven
sudo rm -f /etc/profile.d/maven.sh
sudo rm -f /usr/local/bin/update-maven.sh
Remove Maven Cache and User Data
Warning: The following command permanently deletes your local Maven repository, including all downloaded dependencies and cached artifacts. This frees disk space but requires re-downloading dependencies for future projects.
rm -rf ~/.m2
Finally, verify Maven is completely removed:
which mvn
If Maven is fully removed, this command produces no output. Remember to open a new terminal session to ensure the PATH changes take effect.
Conclusion
You now have Apache Maven installed on Fedora, ready to manage Java project builds, dependencies, and lifecycle tasks. The DNF method provides automatic updates through your system’s package manager, while the tarball method with automated version detection keeps you on the latest release with minimal manual intervention. For ongoing projects, review Maven’s official guides to explore dependency management, plugin configuration, and multi-module project structures. If you work with multiple languages, you may also find our guide on installing Go on Fedora useful for polyglot development environments.