Introduction

This guide explains Install Maven on Ubuntu 24.04 in a production-aware way, including the design choices, implementation checks, and operational safeguards that matter for Linux environments.

Prerequisites

Use a supported release, a tested backup, administrative access, a maintenance window when required, and a rollback plan. Validate DNS, time synchronization, firewall rules, storage, and monitoring before implementation.

Architecture and Core Concepts

Understand the data flow, trust boundaries, dependencies, and the expected state before changing a live environment. Separate control-plane configuration from data-plane traffic and document every external dependency.

Security Considerations

Production safety

  • Do not expose management interfaces or databases to the public Internet.
  • Store passwords, tokens, and private keys outside the article and source repository.
  • Patch dependencies, restrict administrative access, and retain audit logs.

Before we start

Maven downloads Java project dependencies and runs builds and tests. We will install it on Ubuntu 24.04 LTS with a sudo account and internet access. Run these commands in Bash.

As checked on 14 October 2026, the official download page recommends Maven 3.10.0. We use its binary archive to install that exact release. For a later version, check the official download page and adjust the version below.

1. Install Java

Start with OpenJDK 21, available in Ubuntu 24.04. If your project requires a different JDK, use the version specified by the project.

BASH
sudo apt update
sudo apt install -y openjdk-21-jdk-headless curl ca-certificates
java -version
javac -version

Both version commands should report 21. If several JDKs are installed, make sure java and javac point to the intended version before continuing.

2. Download Maven

Create a working folder and download the archive and its SHA-512 checksum from Apache. This avoids relying on the Maven version bundled with Ubuntu.

BASH
mkdir -p ~/maven-install
cd ~/maven-install
MAVEN_VERSION=3.10.0
curl -fLO "https://dlcdn.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz"
curl -fLO "https://downloads.apache.org/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz.sha512"
printf '%s  %s\n' "$(cat apache-maven-${MAVEN_VERSION}-bin.tar.gz.sha512)" "apache-maven-${MAVEN_VERSION}-bin.tar.gz" | sha512sum -c -

Continue only when the checksum check prints OK. A mismatch means you should download the files again. If the URL returns 404, check the official download page for the current release.

3. Extract the archive

BASH
sudo tar -xzf "apache-maven-${MAVEN_VERSION}-bin.tar.gz" -C /opt
sudo ln -sfnT "/opt/apache-maven-${MAVEN_VERSION}" /opt/maven

Maven lives in /opt, and /opt/maven points to the installed version. If /opt/maven is already a real directory from an earlier installation, inspect it first; do not delete it to make this command work.

4. Add Maven to PATH

Set JAVA_HOME from the selected Java executable, then add Maven to the shell path. The profile file also applies to future login shells.

BASH
JAVA_HOME_PATH="$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")"
printf 'export JAVA_HOME="%s"\n' "$JAVA_HOME_PATH" | sudo tee /etc/profile.d/maven.sh > /dev/null
sudo tee -a /etc/profile.d/maven.sh > /dev/null <<'EOF'
export MAVEN_HOME=/opt/maven
export PATH="$MAVEN_HOME/bin:$PATH"
EOF
source /etc/profile.d/maven.sh
mvn -version

Look for Apache Maven 3.10.0 and Java version 21. That confirms the shell can find both tools. Maven is a command-line tool; it does not need a systemd service or an open network port.

5. Run a build

In an existing Maven project, open the folder containing pom.xml and run the command below as your normal user. Maven downloads dependencies on the first run, so that build can take longer.

BASH
mvn clean verify

BUILD SUCCESS means the project completed its configured build and checks. Dependencies are normally cached in ~/.m2/repository. Do not run builds with sudo: it can leave files owned by root in your project or cache.

If something goes wrong

mvn: command not found: source /etc/profile.d/maven.sh again and run command -v mvn. If an older version appears, run type -a mvn to see which installation comes first in PATH.

JAVA_HOME errors: check echo "$JAVA_HOME" and "$JAVA_HOME/bin/java" -version. If you change JDK later, update JAVA_HOME in /etc/profile.d/maven.sh. Missing pom.xml: move into the project folder. Dependency download errors: check internet access and any proxy configured by your organization.

Troubleshooting

SymptomCause / CheckResolution
Service does not startCheck service status, logs, ports, permissions, and configuration syntax.Fix the reported dependency or syntax error, then restart and verify health checks.
Clients cannot connectValidate DNS, routing, firewall policy, TLS, and listening address from both endpoints.Allow only the required source and destination, reload safely, and retest with a controlled client.
Change caused an outageCompare the change with the last known-good version and inspect audit and application logs.Rollback the smallest possible change, restore service, then document the root cause and prevention.

Best Practices

  • Version-control configuration and review changes.
  • Use least privilege and explicit allow-lists.
  • Automate repeatable checks and monitor the expected state.
  • Test upgrades and restores before production rollout.

Conclusion

A reliable implementation of Install Maven on Ubuntu 24.04 is more than a successful first run. Keep the configuration documented, observable, recoverable, and aligned with the team's change-management process.

Frequently Asked Questions

Can this procedure be used in production without a maintenance window?

Only when the platform documents a safe reload or the change is isolated and rollback-tested; otherwise schedule a maintenance window.

What should be backed up before making the change?

Back up configuration, credentials held by the service, application data, and the current version of the deployment. Test the restore path.

How do I verify that the change really took effect?

Check the service health endpoint or status, inspect logs and metrics, and run a representative client-side test from the intended network zone.

What is the first check for a timeout or connection refusal?

Check listening ports, routing, firewall policy, DNS resolution, and whether the service is bound to the expected interface.

How should secrets and tokens be handled?

Use a secret manager or protected environment configuration, rotate them after exposure, and never commit them to Git or paste them into tickets.

How can this be automated safely?

Automate idempotent checks first, add dry-run support, require review for destructive operations, and emit logs and exit codes suitable for monitoring.

What should be monitored after deployment?

Monitor availability, error rate, latency, resource saturation, certificate expiry, failed jobs, and configuration drift.

When should I roll back instead of troubleshooting in place?

Rollback when the service is unavailable, data integrity is at risk, or the blast radius is growing faster than you can isolate it. Preserve logs first.

Official References

Apache Maven downloads and current version

Official installation instructions

Getting started with Maven projects

Share

Meet AJInfrastructure & DevOps
Loading…