July 10, 2026
Tutorials

How to Install Apache Maven on Ubuntu 26.04 (Step-by-Step Guide)

Install Apache Maven on Ubuntu 26.04

Apache Maven is the backbone of most Java build pipelines, and if you’ve just moved to Ubuntu 26.04 LTS (“Resolute Raccoon”), you’ll want to get it running correctly from day one. This guide walks you through every method of installing Maven on Ubuntu 26.04, from the quick APT method to the manual binary install that gives you the latest version, plus environment setup, verification, and troubleshooting tips based on real-world configurations.

Whether you’re setting up a fresh dev machine, a CI/CD build server, or a Docker base image, this tutorial covers the exact commands you need.

Table of Contents

What Is Apache Maven and Why You Need It

Maven is a build automation and project management system for Java applications. It handles applications’ dependencies, compilation of source code, running tests, and packaging of apps into jars or wars by reading from a Project Object Model (POM) file. For those developing with Spring Boot, Java microservices, or any enterprise Java code base, Maven is likely a part of your tool chain.

The current stable release is Apache Maven 3.9.16, which requires JDK 8 or later to run (though most modern projects use JDK 17 or 21). This guide installs that version, along with the Java prerequisite.

Prerequisites Before You Install Maven on Ubuntu 26.04

Before installing Maven, make sure you have:

  • A working installation of Ubuntu 26.04 LTS (desktop or server edition)
  • A user account with sudo privileges
  • An active internet connection
  • Java Development Kit (JDK) installed, Maven will not run without it

Let’s confirm Java is installed first, since it’s the single most common cause of Maven installation failures.

How to Install Apache Maven on Ubuntu 26.04

Install Apache Maven on Ubuntu 26.04 using APT or the latest official binary release after installing Java. This guide provides step-by-step commands to install, configure MAVEN_HOME, and verify the Maven installation.

Follow best practices to set up Apache Maven for reliable Java project development on Ubuntu 26.04.

Step 1: Update Your System Packages

Always start with an updated package index. Open your terminal (Ctrl+Alt+T) and run:

sudo apt update

  sudo apt update

This ensures you’re pulling the latest metadata from Ubuntu 26.04’s repositories before installing anything new.

Step 2: Install Java (JDK), A Required Dependency

Maven runs on the Java Virtual Machine, so you need a JDK installed first. Ubuntu 26.04 ships OpenJDK in its default repositories. Install a current LTS Java version with:

sudo apt install openjdk-21-jdk -y

  sudo apt install openjdk-21-jdk -y

Step 3: Verify Installed Apache Maven on Ubuntu 26.04

Verify the installation:

java -version

javac -version

java -version

You should see output confirming OpenJDK 21 (or your chosen version) is active. If you manage multiple Java versions, you can switch between them using:

sudo update-alternatives –config java

  sudo update-alternatives --config java

Method 1: Install Maven on Ubuntu 26.04 Using APT (Quick Method)

The fastest way to install Maven is directly through Ubuntu’s default package manager.

Step 1: Install the Maven Package

This method is ideal if you don’t need the absolute latest Maven release and just want something that works out of the box.

sudo apt install maven -y

  sudo apt install maven -y

Step 2: Verify the Installed Maven Package

Once the installation finishes, confirm it worked:

mvn -version

mvn -version

You should see the installed Maven version, the Java version it’s using, and your OS details printed to the terminal.

Note: Ubuntu’s official repositories often lag a few minor versions behind Maven’s official releases. If you need the newest features or bug fixes from the 3.9.X line, use the manual installation method below instead.

Method 2: Install the Latest Apache Maven Version Manually (Recommended)

This method installs Maven directly from the official Apache Maven binaries, giving you full control over the version and guaranteeing you’re running the latest release, currently Maven 3.9.16.

Step 1: Download the Maven Binary

Navigate to a temporary directory and download the official archive:

cd /tmp

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

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

Always download from dlcdn.apache.org, Apache’s official distribution mirror network, to avoid tampered third-party sources, a key security practice for any production environment.

Step 2: Extract the Archive

This extracts Maven into /opt/maven, a standard location for optional software packages on Debian-based systems like Ubuntu 26.04.

sudo mkdir -p /opt/maven

sudo tar -xzf apache-maven-3.9.16-bin.tar.gz -C /opt/maven –strip-components=1

  sudo tar -xzf apache-maven-3.9.16-bin.tar.gz -C /opt/maven --strip-components=1

Step 3: Set Environment Variables (PATH and MAVEN_HOME)

To run mvn commands from anywhere in the terminal, add the Maven user to your system PATH. Create a dedicated profile script:

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

Paste the following into the file:

export MAVEN_HOME=/opt/maven

export PATH=$MAVEN_HOME/bin:$PATH

  export PATH=$MAVEN_HOME/bin:$PATH

Save the file (Ctrl+O, Enter, Ctrl+X), then apply the changes:

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

source /etc/profile.d/maven.sh

  source /etc/profile.d/maven.sh

Step 4: Verify the Maven Installation

Run the version check command:

mvn -version

mvn -version

If you see this, Maven is correctly installed and linked to your Java environment.

Setting JAVA_HOME for Maven (Common Fix)

If Maven throws a JAVA_HOME is not defined correctly error, set it explicitly:

sudo update-alternatives –config java

  sudo update-alternatives --config java

Copy the path shown (typically /usr/lib/jvm/java-21-openjdk-amd64), then add it to the same profile file:

export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64

  export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64

Reload your shell with source /etc/profile.d/maven.sh and re-run mvn -version to confirm.

Creating Your First Maven Project

To confirm everything works end-to-end, generate a simple project using Maven’s archetype plugin:

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

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

Navigate into the new project and build it:

cd demo-app

mvn package

mvn package

If the build finishes with BUILD SUCCESS, your Maven installation on Ubuntu 26.04 is fully functional.

Troubleshooting Common Maven Installation Issues on Ubuntu

  • “mvn: command not found.” Your PATH wasn’t updated correctly. Re-run source /etc/profile.d/maven.sh or restart your terminal.
  • Wrong Java version detected. Check JAVA_HOME and use update-alternatives to switch versions.
  • Permission denied errors. Ensure you use sudo for directory creation and extraction steps.
  • Old Maven version from APT. Remove it with sudo apt remove maven -y and follow Method 2 instead.

How to Update Maven on Ubuntu 26.04

Because Apache Maven has no LTS branch, only the two newest minor releases receive security and bug fixes. To update, repeat Method 2 with the newer version number, point MAVEN_HOME to the new directory, and remove the old one once you’ve confirmed the new version works.

Final Thoughts

Install Apache Maven on Ubuntu 26.04 by first installing Java, then using APT or downloading the latest Maven binary. Configure the MAVEN_HOME environment variable and verify the installation with mvn -version.

Installing Apache Maven on Ubuntu 26.04 takes only a few minutes, whether you choose the quick APT route or the manual binary install for the latest release. For most developers and production build servers, the manual method is worth the extra two steps since it keeps you aligned with Apache’s official release cycle rather than Ubuntu’s package lag.

Once installed, Maven becomes the engine behind your entire Java build lifecycle, from dependency resolution to packaging and deployment, so it’s worth taking the extra minute to verify that JAVA_HOME and MAVEN_HOME are configured correctly before you start building real projects.

FAQs

1. How do I install Apache Maven on Ubuntu 26.04?
You can install Apache Maven on Ubuntu 26.04 using the APT package manager or by downloading the latest binary release from the Apache website for the newest version.

2. How do I check the Maven version after installation?
Run the command mvn -version to verify that Apache Maven is installed correctly and to display the installed Maven and Java versions.

3. Do I need Java before installing Apache Maven?
Yes. Apache Maven requires Java to run. Install OpenJDK 17 or a later supported version before installing Maven on Ubuntu 26.04.

4. How do I set the MAVEN_HOME environment variable in Ubuntu 26.04?
Add the MAVEN_HOME and Maven bin directory to your shell profile (such as .bashrc or .profile), then reload the profile to make the changes effective.

5. How do I update Apache Maven to the latest version on Ubuntu 26.04?
Download the latest Apache Maven release, replace the existing installation, update the MAVEN_HOME path if necessary, and verify the upgrade using mvn -version.

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video