Maven runs on Java and lets you build, test, and manage dependencies for any Java project from the command line. There’s no installer — you download a binary archive, unpack it, and point your system to the mvn executable. The whole process takes under ten minutes on any operating system.

What You Need Before Installing Apache Maven

Maven is Java-based, so a JDK must be on your machine before anything else. Download a matching JDK from Oracle’s Java SE page. Pick a folder with no spaces in its path when installing.

Once Java is installed, confirm the commands are available in your PATH by running:

java -version

If the terminal prints a version number, Java is ready. If not, add the JDK’s bin directory to your PATH variable before proceeding.

The file you download depends on your OS:

Operating SystemFile TypeExample
WindowsZIP packageapache-maven-3.9.16-bin.zip
Linuxtar.gz binaryapache-maven-3.9.16-bin.tar.gz
macOStar.gz binaryapache-maven-3.9.16-bin.tar.gz

How to Install Maven on Windows

Go to the Apache Maven download page and grab the latest ZIP release, such as apache-maven-3.9.16-bin.zip. Extract it to a directory of your choice — somewhere like C:\Program Files\apache-maven-3.9.16 works fine.

Setting Environment Variables on Windows

Open System Properties, go to Advanced, and click Environment Variables. Create two new system variables:

  • M2_HOME — set the value to your Maven folder path
  • MAVEN_HOME — same path as M2_HOME

Then find the Path variable under System Variables, click Edit, and add a new entry:

%M2_HOME%\bin

Open a new Command Prompt and run:

mvn -version

The output will show the Maven version, Java version, and OS details. Maven is now working on Windows.

How to Install Maven on Linux

Head to the Apache Maven site and download the latest tar.gz binary. Most distributions — Red Hat, Ubuntu, Debian — use Bash as the default shell, so the commands below apply to all of them.

Create a directory to hold Maven:

$ mkdir -p /usr/local/apache-maven/apache-maven-3.9.16

The mkdir command with the -p flag creates the full directory path in one shot. Then extract the archive:

$ tar -xvf apache-maven-3.9.16-bin.tar.gz -C /usr/local/apache-maven/apache-maven-3.9.16

The tar command unpacks the archive into the target directory. For more on working with compressed files, the guide on extracting tar.gz files covers additional options.

Setting the PATH Variable on Linux

Open your .bashrc file in a text editor:

$ nano ~/.bashrc

Add these lines at the bottom:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.9.16
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m
export PATH=$M2:$PATH

Save and close the file, then reload without restarting the session:

$ source ~/.bashrc

Run mvn -version to confirm. For a deeper look at how PATH works on Linux, that covers the mechanics behind why this step is needed.

Installing Maven on Ubuntu Using apt

Ubuntu users can skip the manual download entirely and use the package manager. First, check what’s available:

$ apt-cache search maven

The maven package in the results always points to the latest Apache Maven. Install it with:

$ sudo apt-get install maven

The apt-get command handles the download and setup automatically. The download takes a few minutes. Once it finishes, run:

mvn -version

How to Install Maven on Mac

Download the latest tar.gz binary from the Apache Maven site and extract it to a location you prefer. The file you edit for PATH depends on which macOS version you’re running:

macOS VersionDefault ShellFile to Edit
Older releasesbash$HOME/.profile
Catalina and newerzsh~/.zshenv
High Sierrabash$HOME/.bashrc

Setting the PATH Variable on Mac (Pre-Catalina)

Open Terminal and log in as superuser. Remove the archive once extraction is complete:

rm Downloads/apache-maven*bin.tar.gz

Set the correct owner using chown, then move the files into place:

chown -R root:wheel Downloads/apache-maven*
mv Downloads/apache-maven* /opt/apache-maven

Exit the admin session, then open your profile file:

exit
nano $HOME/.profile

Add the following line:

export PATH=$PATH:/opt/apache-maven/bin

Press Ctrl+X to save and exit nano. Load the changes by typing bash, then verify:

mvn -version

PATH Setup for macOS Catalina and Later

From Catalina onward, Apple switched the default shell from bash to Z shell (zsh). Zsh behaves similarly to bash but adds smarter tab completion and a module system. The file you edit is different:

nano ~/.zshenv

Add the same line:

export PATH=$PATH:/opt/apache-maven/bin

Reload with source ~/.zshenv. After that, mvn -version should print the build info without error.

High Sierra PATH Setup

On High Sierra, the process is the same as pre-Catalina but uses .bashrc instead of .profile:

nano $HOME/.bashrc
export PATH=$PATH:/opt/apache-maven/bin

Press Ctrl+X to save, then run bash to apply it.

Verifying Your Maven Installation

On all three operating systems, the final check is the same command:

mvn -version

A working installation prints something like:

Apache Maven 3.9.16 (...)
Maven home: /usr/local/apache-maven/apache-maven-3.9.16
Java version: 17.0.10, vendor: Oracle Corporation
OS name: "linux", version: "5.15.0"

If the command isn’t found, the most common cause is a missing or incorrect PATH entry. Double-check that the bin directory path matches where Maven was extracted, and that the config file was reloaded after editing.

FAQs

Does Maven require Java to be installed first?

Yes. Maven is a Java-based tool and won’t run without a JDK. Install JDK 8 or higher, verify it with java -version, and make sure the JDK’s bin folder is in your PATH before installing Maven.

What is the difference between M2_HOME and MAVEN_HOME?

Both point to the Maven installation directory. MAVEN_HOME replaced M2_HOME in Maven 3.x, but setting both ensures compatibility with older tools and scripts that still reference M2_HOME.

Can Maven be installed on Ubuntu without downloading the archive manually?

Yes. Run sudo apt-get install maven and the package manager installs it automatically. This is the faster option for Ubuntu and Debian users who don’t need a specific Maven version.

Why does mvn -version say “command not found” after installation?

The PATH variable wasn’t updated, or the config file wasn’t reloaded. Re-open the terminal or run source ~/.bashrc (Linux) or source ~/.zshenv (macOS Catalina+), then try again.

Which file do I edit for PATH on macOS Catalina?

Edit ~/.zshenv. Catalina replaced bash with zsh as the default shell, so .profile and .bashrc are no longer read by default. Add your export line there and reload with source ~/.zshenv.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.