Installing Maven - Windows

This article gives you a step by step walkthrough for installing Apache Maven on Mac.

You can watch the entire installation demo in this video.

Introduction

Apache Maven is the most popular build and project management tool for Java projects. Maven is built on top of Java, so if you plan to install Maven on your system, you need to have Java installed on your system.

Installation of Maven on any system consists of following 3 steps.

  1. Download the Apache Maven binary zip from the official website
  2. Extracting the binary zip into a specific folder
  3. Configure the environment variables of the System.

Let me walk you through these steps in detail for a Mac system.

Info

The latest Apache Maven version at the time of writing this is 3.9.9. All screenshots and commands in this article refer to this version. But they are equally applicable to other versions, as well.

1. Downloading the Apache Maven

The first step is to download the Apache Maven from the official website. The downloads page for Apache Maven is this - https://maven.apache.org/download.cgi. On this page, you have two binary options to download - either a zip file or a tar.gz file(marked in blue boxes). Here is the screenshot below.

Screenshot of Maven Downloads page listing different binaries | The Developer Journal Screenshot of Maven Downloads page listing different binaries | The Developer Journal

You can choose either of these. If you are not sure, choose the zip file. Also, download the corresponding checksum file (marked in orange boxes) so that you can validate the zip file download.

You can use your browser to download these, or you can use the curl on the command prompt to download the files.

Here is the command using the curl that download the zip file and the corresponding checksum file.

PS C:\Users\thedevjournal\Downloads> curl -o apache-maven-3.9.9-bin.zip https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.zip

PS C:\Users\thedevjournal\Downloads> curl -o apache-maven-3.9.9-bin.zip.sha512 https://downloads.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.zip.sha512

PS C:\Users\thedevjournal\Downloads> dir

    Directory: C:\Users\thedevjournal\Downloads

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        02-02-2025     05:18        9202456 apache-maven-3.9.9-bin.zip
-a----        02-02-2025     05:22            128 apache-maven-3.9.9-bin.zip.sha512

2. Extracting the Binary archive File

2.1. Verifying the Checksum

Before you extract the zip file, perform a quick checksum validation of the downloaded file to ensure that there were no issues with the download.

The checksum files mentions which kind of hash is used for zip file. Windows provides CertUtil which allows to generate checksum of files using -hashfile operation. Since the Maven checksum file uses SHA-512 format, we also need to generate the hash in the same format.

PS C:\Users\thedevjournal\Downloads> CertUtil -hashfile .\apache-maven-3.9.9-bin.zip SHA512

SHA512 hash of .\apache-maven-3.9.9-bin.zip:
8beac8d11ef208f1e2a8... (removed in favour of brevity) ...82ee8a2ff4c4418ba
CertUtil: -hashfile command completed successfully.


PS C:\Users\thedevjournal\Downloads> cat .\apache-maven-3.9.9-bin.zip.sha512
8beac8d11ef208f1e2a8... (removed in favour of brevity) ...82ee8a2ff4c4418ba

A quick glance, you would see that both the checksums are same and that ensures that the download was completed without any errors.

2.2. Installation Directory

Before we extract the binary archive file, we need a directory. It is a good practice to keep all of your installations together, so you can place them in a directory called installed in your C drive(C:\).

You can create this directory if it does not exist using the mkdir command.

PS C:\Users\thedevjournal\Downloads> mkdir C:\installed

Afterwards, we need to move our binary archive file inside C:\installed directory, and then we cd into this directory so that we can extract the archive file here.

PS C:\Users\thedevjournal\Downloads> mv apache-maven-3.9.9-bin.zip C:\installed

PS C:\Users\thedevjournal\Downloads> cd C:\installed

2.3. Extracting the Binary file

You will use Expand-Archive command to extract the contents of the zip file.

PS C:\installed> Expand-Archive .\apache-maven-3.9.9-bin.zip
PS C:\installed> dir

    Directory: C:\installed

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        02-02-2025     05:35                apache-maven-3.9.9-bin
-a----        02-02-2025     05:18        9202456 apache-maven-3.9.9-bin.zip

PS C:\installed> dir .\apache-maven-3.9.9-bin\

    Directory: C:\installed\apache-maven-3.9.9-bin

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        02-02-2025     05:35                apache-maven-3.9.9

Expand-Archive extracts the file contents inside the apache-maven-3.9.9-bin directory, hence we also need to move the new extracted folder 1 level above. And then, we can delete the zip file and the empty extraction folder.

PS C:\installed> mv .\apache-maven-3.9.9-bin\apache-maven-3.9.9 .\

PS C:\installed> rmdir .\apache-maven-3.9.9-bin

PS C:\installed> rmdir .\apache-maven-3.9.9-bin.zip

PS C:\installed> dir

    Directory: C:\installed

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        02-02-2025     06:24                apache-maven-3.9.9
Note

You can also simply extract from UI as well.

Configure the Environment Variables

With the extraction of binary archive file in the installed directory, Maven is pretty much installed in your system. The only gotcha is that every-time you need to run the mvn command, you will have to traverse the entire path - C:\installed\apache-maven-3.9.9\bin\mvn. It will be much better, if we could just run the mvn command from any directory without specifying the entire path to the mvn executable.

A lot of Java tools look for M2_HOME environment variable to locate the Maven installation directory in the system. This environment variable can be configured using [System.Environment]::SetEnvironmentVariable. This is the command:

[System.Environment]::SetEnvironmentVariable('M2_HOME','C:\installed\apache-maven-3.9.9', 'User')
Note

The 3rd parameter, User indicates that you intend to store this variable across multiple sessions, and only available to the user who is logged in. If you want to set this variable system-wide, use Machine as the parameter.

Once, this is configured, we need to configure the PATH variable, that will enable running of the mvn command from any directory. Here is how, it will be configured:

$OLD_PATH = [Environment]::GetEnvironmentVariable("PATH", "User")
[Environment]::SetEnvironmentVariable("PATH", "$OLD_PATH;%M2_HOME%\bin", "User")

Once this is configured, you need to re-import the configurations. Simple close the current terminal window and open a new one.

And now if you run mvn -version, you should see the Maven installation details confirming that you have Apache Maven installed successfully.

PS C:\installed> mvn --version

Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: C:\installed\apache-maven-3.9.9
Java version: 17.0.14, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-17
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"



Now, you can start to run your builds locally with Maven on your Mac system.