| Tested on | Ubuntu 26.04 LTS (host) Ubuntu 24.04 LTS & 22.04 LTS (Docker, apt-cache policy) |
|---|---|
| Package | maven 3.9.12-1default-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 |
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:
sudo apt updateInstall 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):
sudo apt install default-jdk mavenConfirm the compiler and Maven agree on Java:
javac -version
mvn -versionExample on Ubuntu 26.04 after install:
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-amd64APT 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 globalmvnis often unnecessary - Need newer Maven than apt →
./mvnwor 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:
apt-cache policy maven default-jdkChoose 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
./mvnwwithout a globalmvninstall
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):
./mvnw -versionBuild with the wrapper instead of a global mvn:
./mvnw packageUse 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:
sudo apt update
sudo apt install default-jdkVerify the runtime and compiler:
java -version
javac -versionIf 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:
mvn -versionThe 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:
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:
apt-cache policy mavenIn 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:
sudo apt install mavenConfirm which mvn binary runs and which Java Maven picked up:
command -v mvn
mvn -versionExample on 26.04:
/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-amd64Apt 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/mvncan coexist- Whichever
bindirectory appears first onPATHwins - You do not need
sudo apt purge mavenfirst
Download Maven 3.10.0
Apache publishes binaries and checksums on the download page. Download the archive and its SHA-512 file:
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.sha512Verify the SHA-512 checksum
Apache's .sha512 file contains only the hash. Verify before extracting:
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:
sudo tar -xzf apache-maven-3.10.0-bin.tar.gz -C /optCreate the /opt/maven symlink
Point a stable path at the versioned directory so upgrades only retarget the symlink:
sudo ln -sfn /opt/apache-maven-3.10.0 /opt/mavenAdd Maven to PATH
Apache's install instructions only require bin on PATH—no M2_HOME or MAVEN_HOME for normal use:
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.shWhere 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:
type -a mvnmvn is /opt/maven/bin/mvn
mvn is /usr/bin/mvnThe first entry wins. Confirm the version:
mvn -versionApache Maven 3.10.0 (c43a36b8d67be7e0805a411bc0898af1a51f5472)
Maven home: /opt/maven
Java version: 25.0.4.1, vendor: Ubuntu, runtime: /usr/lib/jvm/java-25-openjdk-amd64To 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):
mkdir -p ~/maven-hello && cd ~/maven-helloGenerate a minimal project non-interactively:
mvn archetype:generate \
-DgroupId=com.example \
-DartifactId=hello \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.5 \
-DinteractiveMode=false[INFO] Project created from Archetype in dir: .../maven-hello/hello
[INFO] BUILD SUCCESSBuild the project
Move into the project directory and run the full lifecycle:
cd helloFrom the project root, compile, run tests, and build the JAR:
mvn package[INFO] BUILD SUCCESSRun the generated JAR
Run the sample App class:
java -cp target/hello-1.0-SNAPSHOT.jar com.example.AppHello World!A successful quickstart build confirms:
- Maven runs and resolves plugins
- The JDK compiler (
javac) works - Maven Central is reachable from this host
~/.m2/repositoryis populated for later builds
Update Maven on Ubuntu
Update APT-installed Maven
Refresh indexes and upgrade the package:
sudo apt updateUpgrade only the Maven package when a newer revision is in the archives:
sudo apt install --only-upgrade mavenRe-check apt-cache policy maven if you need the new Debian revision.
Update a manual /opt installation
To bump a manual install:
- Download and verify the newer 3.10.x (or future) tarball
- Extract to
/opt/apache-maven-VERSION - Test with
/opt/apache-maven-VERSION/bin/mvn -version - Repoint the symlink:
sudo ln -sfn /opt/apache-maven-3.10.0 /opt/mavenAdjust 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:
sudo apt remove mavenPreview packages apt might autoremove before you confirm:
sudo apt-get -s autoremoveRemoving 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.
sudo rm /opt/maven
sudo rm -rf /opt/apache-maven-3.10.0
sudo rm /etc/profile.d/maven.shBroader 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
- Apache Maven — Installation
- Apache Maven — Download
- Apache Maven — Wrapper
- Apache Maven — Toolchains
- Maven in 5 Minutes
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.

