How to Install Apache Maven on Ubuntu

Deepak Prasad
Tested on Ubuntu 26.04 LTS (host)
Ubuntu 24.04 LTS & 22.04 LTS (Docker, apt-cache policy)
Package maven 3.9.12-1
default-jdk → OpenJDK 25 (openjdk-25-jdk)
Applies to Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS; commands tested on amd64
Privilege sudo for apt and /opt; normal user for builds and ~/.m2
Scope Install Apache Maven with a suitable JDK, pick apt, the project Maven Wrapper (./mvnw), or the current Apache 3.10 binary; verify with mvn -version and a quickstart build. Does not cover multi-module projects, repository managers, or CI/CD.
Related guides Install Java on Linux, Windows, and Mac
apt command in Linux
check Ubuntu version
How to remove software on Ubuntu
Short on time?Beta Get the gist of this 11-minute read in seconds, then ask follow-up questions

Apache Maven reads the project's pom.xml build file, resolves dependencies from Maven Central (the default public repository where Maven downloads most Java libraries and plugins), and runs lifecycle phases such as compile, test, and package. On Ubuntu you need a JDK (not a JRE-only package) and a way to run mvn—either the distro package, the project's Maven Wrapper, or a current release from Apache.

Install Maven on Ubuntu, confirm which JDK mvn uses, and finish with a real quickstart build. The sample output below is from Ubuntu 26.04 with Maven 3.9.12 from apt and OpenJDK 25 from default-jdk. The same workflow applies on 24.04 and 22.04; only the apt Maven and default JDK versions differ.


Quick answer: Maven on Ubuntu by release

For the simplest Ubuntu-managed setup, install a JDK and Maven together:

bash
sudo apt update

Install the metapackage that tracks Ubuntu's default JDK plus Maven from Universe (Ubuntu's community-maintained package component, where maven is published on these LTS releases):

bash
sudo apt install default-jdk maven

Confirm the compiler and Maven agree on Java:

bash
javac -version
mvn -version

Example on Ubuntu 26.04 after install:

output
javac 25.0.4.1
Apache Maven 3.9.12
Maven home: /usr/share/maven
Java version: 25.0.4.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-25-openjdk-amd64

APT Maven versions by Ubuntu LTS:

  • 26.04: Maven 3.9.12
  • 24.04: Maven 3.8.7
  • 22.04: Maven 3.6.3

Upstream: Apache Maven 3.10.0 is the current recommended release; 3.9.16 is the previous maintained 3.9 line. Apache has ended support for older lines such as 3.8 and 3.6—that is separate from Ubuntu's security maintenance of distro packages.

When apt is not enough:

  • Project has ./mvnw → use the wrapper; a global mvn is often unnecessary
  • Need newer Maven than apt → ./mvnw or the official binary under /opt
  • Do not replace Ubuntu's entire Java stack just to bump Maven

Maven versions on Ubuntu 26.04, 24.04, and 22.04

Ubuntu APT maven Default JDK (default-jdk) Practical note
26.04 LTS 3.9.12 OpenJDK 25 Apt is fine for many builds; use 3.10 or ./mvnw when plugins need a newer Maven
24.04 LTS 3.8.7 OpenJDK 21 Prefer Maven Wrapper or Apache 3.10 for new projects that track current plugins
22.04 LTS 3.6.3 OpenJDK 11 Strongly prefer Wrapper or Apache 3.10 for modern development

Upstream (October 2026):

  • 3.10.0 — current recommended release
  • 3.9.16 — previous 3.9 maintenance line
  • Maven 4 — preview release candidate; Apache does not recommend it for production

Confirm candidates on your machine with check Ubuntu version and:

bash
apt-cache policy maven default-jdk

Choose a Maven installation method

        ┌─────────────────────────────┐
        │ Existing Java project repo? │
        └──────────────┬──────────────┘
                       │
          ┌────────────┴────────────┐
          ▼                         ▼
┌────────────────────┐    ┌────────────────────┐
│ Contains ./mvnw    │    │ No wrapper         │
│ Use Maven Wrapper  │    │ Install Maven      │
└────────────────────┘    └─────────┬──────────┘
                                    │
                    ┌───────────────┴───────────────┐
                    ▼                               ▼
          ┌────────────────────┐         ┌────────────────────┐
          │ Ubuntu apt         │         │ Apache 3.10 binary │
          │ simplest on 26.04  │         │ current / exact    │
          └────────────────────┘         └────────────────────┘
Situation Recommended method
Ubuntu 26.04, general local builds sudo apt install default-jdk maven
Project includes mvnw / .mvn/ Maven Wrapper—no global mvn required
24.04 / 22.04 + modern plugins Wrapper or Apache 3.10 binary
Need exact current Maven release Official tarball under /opt/maven

Use the Maven Wrapper when your project includes mvnw

If the repository contains mvnw and .mvn/wrapper/, it uses the Maven Wrapper:

  • Pins the Maven version the project expects
  • Downloads that distribution on first run (into your user Maven area)
  • Lets you run ./mvnw without a global mvn install

Windows-oriented repositories may also include mvnw.cmd.

You still need a JDK on the machine. From the project root, run the wrapper (use chmod +x mvnw only if the script is not already executable):

bash
./mvnw -version

Build with the wrapper instead of a global mvn:

bash
./mvnw package

Use this path before installing apt Maven when you only work inside one cloned project.


Install Java for Maven

Maven is a Java application (Maven install guide):

  • Maven 3.10 needs JDK 8+ to launch
  • Normal Java builds need javac, so install a JDK, not a JRE-only package
  • The JDK that starts Maven can differ from the Java version your project compiles against

Install Ubuntu's default JDK

For a general workstation install, use the metapackage:

bash
sudo apt update
sudo apt install default-jdk

Verify the runtime and compiler:

bash
java -version
javac -version

If your project must target a specific release (for example 17 or 21), install that JDK package explicitly instead of relying on default-jdk. See install Java on Linux, Windows, and Mac for other distributions and vendors.

JAVA_HOME when Maven needs it

Many Ubuntu setups work when java and javac are on PATH. Run:

bash
mvn -version

The output lists Java version and Java home. Set JAVA_HOME only when a tool or error message requires it. Common choices on Ubuntu:

  • /usr/lib/jvm/default-java (tracks the default JDK metapackage)
  • Derive from the compiler on PATH:
bash
JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")"
echo "$JAVA_HOME"

Maven can launch on one JDK while compiling for another. Maven Toolchains lets a project select a separate JDK for compilation without changing the JDK that launches Maven—use that instead of constantly retargeting the system default Java.


Install Maven with APT on Ubuntu

Check the Maven package before you install

Inspect what apt will install:

bash
apt-cache policy maven

In apt-cache policy output, Candidate is the package version APT would install right now. On Ubuntu 26.04 the Maven candidate is typically 3.9.12-1 from resolute/universe.

Install Maven from apt

Install Maven with apt:

bash
sudo apt install maven

Confirm which mvn binary runs and which Java Maven picked up:

bash
command -v mvn
mvn -version

Example on 26.04:

output
/usr/bin/mvn
Apache Maven 3.9.12
Maven home: /usr/share/maven
Java version: 25.0.4.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-25-openjdk-amd64

Apt layout:

Path Role
/usr/bin/mvn Launcher (may coexist with /opt/maven/bin/mvn)
/usr/share/maven Maven home for distro package
/etc/maven/ System-wide settings
~/.m2/repository Local dependency cache

Install current Apache Maven manually

Use this when you need Maven 3.10.0 (or a specific Apache build) while keeping apt Maven installed:

  • /usr/bin/mvn (apt) and /opt/maven/bin/mvn can coexist
  • Whichever bin directory appears first on PATH wins
  • You do not need sudo apt purge maven first

Download Maven 3.10.0

Apache publishes binaries and checksums on the download page. Download the archive and its SHA-512 file:

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

Verify the SHA-512 checksum

Apache's .sha512 file contains only the hash. Verify before extracting:

bash
printf '%s  %s\n' \
  "$(cat apache-maven-3.10.0-bin.tar.gz.sha512)" \
  "apache-maven-3.10.0-bin.tar.gz" | sha512sum -c -

A successful check prints apache-maven-3.10.0-bin.tar.gz: OK. Apache also publishes PGP signatures for stronger verification; use them when your policy requires it.

Extract Maven under /opt

Extract the verified archive:

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

Point a stable path at the versioned directory so upgrades only retarget the symlink:

bash
sudo ln -sfn /opt/apache-maven-3.10.0 /opt/maven

Add Maven to PATH

Apache's install instructions only require bin on PATH—no M2_HOME or MAVEN_HOME for normal use:

bash
sudo tee /etc/profile.d/maven.sh >/dev/null <<'EOF'
export PATH="/opt/maven/bin:$PATH"
EOF
sudo chmod 0644 /etc/profile.d/maven.sh
source /etc/profile.d/maven.sh

Where to put the PATH export:

  • /etc/profile.d/maven.sh — all users on login (what this guide uses)
  • ~/.profile — single-user setup only

Open a new login shell if mvn is still the apt build.

Verify which Maven is active

List every mvn on PATH:

bash
type -a mvn
output
mvn is /opt/maven/bin/mvn
mvn is /usr/bin/mvn

The first entry wins. Confirm the version:

bash
mvn -version
output
Apache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: /opt/maven
Java version: 25.0.4.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-25-openjdk-amd64

To prefer apt Maven again, remove /etc/profile.d/maven.sh or change PATH so /usr/bin appears before /opt/maven/bin.


Test Maven with a Hello World project

The first mvn package on a new machine downloads plugins and dependencies into ~/.m2/repository; later builds reuse that cache.

Generate the Maven Quickstart project

Use archetype 1.5 (defaults to Java 17 in the generated POM—no Java 7 workaround):

bash
mkdir -p ~/maven-hello && cd ~/maven-hello

Generate a minimal project non-interactively:

bash
mvn archetype:generate \
  -DgroupId=com.example \
  -DartifactId=hello \
  -DarchetypeGroupId=org.apache.maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DarchetypeVersion=1.5 \
  -DinteractiveMode=false
output
[INFO] Project created from Archetype in dir: .../maven-hello/hello
[INFO] BUILD SUCCESS

Build the project

Move into the project directory and run the full lifecycle:

bash
cd hello

From the project root, compile, run tests, and build the JAR:

bash
mvn package
output
[INFO] BUILD SUCCESS

Run the generated JAR

Run the sample App class:

bash
java -cp target/hello-1.0-SNAPSHOT.jar com.example.App
output
Hello World!

A successful quickstart build confirms:

  • Maven runs and resolves plugins
  • The JDK compiler (javac) works
  • Maven Central is reachable from this host
  • ~/.m2/repository is populated for later builds

Update Maven on Ubuntu

Update APT-installed Maven

Refresh indexes and upgrade the package:

bash
sudo apt update

Upgrade only the Maven package when a newer revision is in the archives:

bash
sudo apt install --only-upgrade maven

Re-check apt-cache policy maven if you need the new Debian revision.

Update a manual /opt installation

To bump a manual install:

  1. Download and verify the newer 3.10.x (or future) tarball
  2. Extract to /opt/apache-maven-VERSION
  3. Test with /opt/apache-maven-VERSION/bin/mvn -version
  4. Repoint the symlink:
bash
sudo ln -sfn /opt/apache-maven-3.10.0 /opt/maven

Adjust the version directory when Apache publishes a new release.


Uninstall Maven on Ubuntu

Remove the Ubuntu package

Drop the distro Maven package when you no longer need /usr/bin/mvn:

bash
sudo apt remove maven

Preview packages apt might autoremove before you confirm:

bash
sudo apt-get -s autoremove

Removing Maven does not delete ~/.m2/repository. That folder may still contain:

  • Downloaded dependencies and plugins
  • Artifacts you installed locally with mvn install

Delete it only when you want Maven to redownload everything and you do not need those local artifacts.

Remove a manual Maven version

Remove the symlink, the specific version directory, and the profile snippet. Check the /opt/apache-maven-... path carefully before you run rm -rf; it permanently deletes that directory.

bash
sudo rm /opt/maven
sudo rm -rf /opt/apache-maven-3.10.0
sudo rm /etc/profile.d/maven.sh

Broader cleanup patterns: How to remove software on Ubuntu.


Troubleshooting Maven on Ubuntu

Symptom Likely cause Fix
mvn: command not found Maven not installed or not on PATH sudo apt install maven or source /etc/profile.d/maven.sh
JAVA_HOME is not defined correctly JDK missing or wrong JAVA_HOME Install default-jdk; use mvn -version to see Java home; set JAVA_HOME to /usr/lib/jvm/default-java if needed
mvn -version shows wrong Maven Multiple installs on PATH type -a mvn; put preferred bin first in PATH
Maven uses wrong Java Different JDK on PATH vs project need Align javac with project; consider Toolchains
Unable to locate package maven Universe disabled or wrong release sudo apt update; enable universe; confirm LTS with check Ubuntu version
./mvnw: Permission denied Wrapper script not executable chmod +x mvnw, then ./mvnw -version
Wrapper fails on first run Cannot download Maven distribution (network, proxy, firewall) Fix connectivity or proxy in ~/.m2/settings.xml; or install Maven from apt or /opt
Dependency download failures Network, proxy, or mirror Configure ~/.m2/settings.xml proxy/mirror
Build requires newer Maven Apt too old for plugin Use ./mvnw or install 3.10 under /opt/maven

Summary

Install a JDK first—default-jdk is the normal choice on current Ubuntu LTS releases—and add Maven with apt when the distro version matches your project. On 26.04, Maven 3.9.12 with OpenJDK 25 is a reasonable default; on 24.04 and 22.04, apt Maven is older, so ./mvnw or Apache 3.10.0 is often the better fit for new work even though Ubuntu still maintains its own packages.

Before you install globally, check for mvnw in the repository. When you install manually, verify the tarball with SHA-512, extract under /opt, symlink /opt/maven, and put only /opt/maven/bin on PATH—apt and /opt Maven can coexist; type -a mvn shows which one runs.

Prove the toolchain with mvn archetype:generate (quickstart 1.5) and mvn package, then run the sample JAR. Expect the first build to populate ~/.m2/repository; treat that directory as more than disposable cache if you have installed artifacts locally.


References


Frequently Asked Questions

Does Ubuntu 26.04 include Maven?

Yes—Maven 3.9.12 is in the universe repository on 26.04. Install it with sudo apt install maven after you install a JDK.

Which Maven version does Ubuntu 24.04 install?

24.04 typically ships Maven 3.8.7 from apt. Run apt-cache policy maven on your system to confirm the candidate.

What is the latest Apache Maven version?

3.10.0 is the current recommended release from Apache. 3.9.16 remains the maintained previous 3.9 line. Maven 4 is still a preview release candidate and Apache does not recommend it for production.

Do I need a JDK or just a JRE?

You need a JDK with javac for normal Java project builds. Maven itself also requires a JDK 8+ to start.

Do I need to set JAVA_HOME?

Not always. If java and javac are on PATH, mvn -version often works. Set JAVA_HOME when tools complain or when you need an explicit JDK path—/usr/lib/jvm/default-java on Ubuntu is a portable choice.

Should I use Maven Wrapper instead of installing Maven?

Yes when the project ships mvnw. The wrapper downloads the project's Maven version; you only install a JDK on the host.

Can apt Maven and /opt Maven coexist?

Yes. Both can be installed. Whichever mvn appears first in PATH wins—use type -a mvn to see order.

Should I install Maven 4?

Not for a normal production setup yet. This guide targets current Maven 3.10; Maven 4 is still a preview release candidate and Apache does not recommend it for production.

Finished reading?Beta Get the key takeaways in seconds, then ask follow-up questions
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration