Maven 3
Ubuntu
apt-get
software installation
Linux commands

How to install Maven 3 on Ubuntu 18.04/17.04/16.10/16.04 LTS/15.10/15.04/14.10/14.04 LTS/13.10/13.04 by using apt-get?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

On Ubuntu, the package-manager answer is usually straightforward: install the maven package. The real complications come from Java prerequisites, end-of-life Ubuntu releases, and the fact that the repository package may not be the newest Maven release published by Apache.

For the Ubuntu versions named in the title, the basic apt-get workflow is the same. If the repositories for that release are still reachable, update package metadata, install a JDK, install Maven, and verify with mvn -v.

Install Maven with apt-get

The most common command sequence is:

bash
sudo apt-get update
sudo apt-get install default-jdk
sudo apt-get install maven

Then verify the installation:

bash
java -version
mvn -v

If mvn -v prints the Maven version and Java runtime details, the installation is usable. Apache's current installation guide commonly shows apt install maven, but on older Ubuntu systems apt-get install maven is the same package-manager idea and was the standard form in many tutorials.

What You Actually Installed

When you use Ubuntu's maven package, you are installing the distro-packaged version of Maven. That is often what you want for:

  • local development on a standard Ubuntu machine
  • CI images that prefer stable packages
  • older Java projects that already align with distro tooling

It is not always the latest upstream Maven release. If you need an exact newer version for a build, Maven Wrapper or a manual Apache binary install is usually a better fit than expecting the Ubuntu package to track upstream immediately.

Test the Installation with a Real Build

Running mvn -v only proves the binary exists. A stronger check is to run a real build:

bash
1mvn -B archetype:generate \
2  -DgroupId=com.example \
3  -DartifactId=demo \
4  -DarchetypeArtifactId=maven-archetype-quickstart \
5  -DinteractiveMode=false

Then build the generated project:

bash
cd demo
mvn test

That verifies Maven can resolve dependencies, read a pom.xml, and invoke Java correctly.

Old Ubuntu Releases and Repository Failures

Several Ubuntu versions listed in the title are long past end of life. That matters because apt-get install maven only works if the configured package repositories still provide packages for that release.

Typical failure modes include:

  • '404 errors during apt-get update'
  • "Unable to locate package maven"
  • missing package candidates in apt-cache policy

When that happens, the issue is often the repository configuration, not Maven itself. Older Ubuntu releases may need archived mirrors instead of the standard active mirrors.

Before changing system configuration, inspect what Ubuntu knows about the package:

bash
apt-cache policy maven

If there is no candidate version, fix the repository source first. Installing Maven cannot succeed until the package metadata is available.

Java and JAVA_HOME

Maven requires a JDK. On Ubuntu, default-jdk is the simplest choice because it installs the release-appropriate development kit.

In many environments you do not need to set JAVA_HOME manually. If mvn -v already reports a Java runtime, Maven found one. Set JAVA_HOME only when you have multiple JDKs or a build requires a specific installation path.

Example:

bash
export JAVA_HOME=/usr/lib/jvm/default-java
export PATH="$JAVA_HOME/bin:$PATH"

That is a troubleshooting step, not part of the normal install sequence.

Common Pitfalls

The biggest mistake is assuming the Ubuntu package gives you the newest Apache Maven version. Repository packages prioritize stability, not immediate freshness.

Another common issue is installing Maven without a JDK and then debugging Java-related failures as if Maven were the problem.

A third problem is trying to use normal mirrors on an end-of-life Ubuntu release without realizing the packages may have moved to archival infrastructure.

Finally, the executable is mvn, not maven. Verify with mvn -v.

Summary

  • On Ubuntu, the package-manager install is usually sudo apt-get install maven.
  • Install a JDK first, typically with sudo apt-get install default-jdk.
  • Verify the setup with mvn -v and ideally a small sample build.
  • On older Ubuntu releases, repository availability is often the real blocker.
  • If you need a specific newer Maven version, prefer Maven Wrapper or a manual Apache install over the distro package.

Course illustration
Course illustration

All Rights Reserved.