Installing Apache Maven on Ubuntu: Setup, Verification, and Tips
09:02, 26.10.2026
Before you start typing build commands and chasing missing libraries, you need a solid foundation. Ideally, you would like your Java projects to build in the same way on every machine. You want fewer surprises and more control.
Apache Maven provides stability, and Ubuntu offers a clean environment in which to run it. This guide will walk you through the step-by-step installation of Maven, help you verify that everything is working correctly, and provide you with tips along the way.
Apache Maven Explained
If you work with Java projects, you will inevitably encounter Apache Maven at some point. Maven helps you to manage dependencies, build code and maintain consistency across your projects. All you have to do is define what you need in a simple configuration file, and Maven takes care of the rest. This saves you time and helps you avoid the chaos of manual setup.
Maven remains one of the most trusted build tools in the Java ecosystem, and it works smoothly on Ubuntu.
Pre-Installation Checklist
Check a few things:
- You need Ubuntu with sudo privileges.
- You also need Java installed, because Maven runs on the Java Virtual Machine.
- You can verify Java by running java -version in the terminal.
Maven officially supports Java 7 and newer, but modern projects usually rely on Java 11 or later. Make sure your system has an active internet connection, since Maven downloads dependencies when you build projects.
Installing with APT
When you install Maven with APT, it gives you speed and simplicity. Ubuntu maintains Maven in its official repositories, so you can trust the source.
Step #1: Refresh Package Index
You must always refresh the package index first. This ensures that Ubuntu recognises the latest available versions. Open your terminal and run the 'sudo apt update' command. This will help your system to stay in sync with the repositories.
Step #2: Install Maven
Now you can install Maven with one command.
Run sudo apt install maven. Ubuntu resolves dependencies for you and places Maven in the correct system paths.
After installation, you can check the version with mvn -version.
You should see Maven details and the Java version it uses.
Installing Maven from a Downloaded Archive
Of course, you may want more control over the Maven version. Manual installation works well when you need a newer release than the one in APT.
Step #1: Download the Maven Distribution
The official Apache website is where you should download Maven. Apache hosts verified binary archives for each release. Select the latest stable version and download the .tar.gz file. This source is trustworthy and up to date.
Step #2: Extract Maven and Create a Symlink
The next step is for the archive to be extracted. A common location for optional software is /opt, so you can place Maven there. After extraction, create a symbolic link to /opt/maven. This lets you upgrade Maven later without changing paths across the system.
Step #3: Set Up Environment Variables
Now you tell Ubuntu where Maven lives. You set the MAVEN_HOME variable and update the PATH. You can place these settings in /etc/profile.d/maven.sh or in your own shell configuration file. This step ensures that you can run mvn from any directory.
Step #4: Confirm the Installation
You should confirm everything works as expected. Run mvn -version again. Maven should report the correct version and detect your Java installation.
At this point, you are ready to build projects.
Wrap-Up
So, you've got Apache Maven up and running on your Ubuntu computer. For convenience, you can choose the APT method, or for flexibility, you can choose the archive method. Both approaches are valid and widely used. With Maven installed, you have a reliable way to manage builds and dependencies. Your Java workflow will become faster, cleaner and far more predictable.