> ## Content Index
> Fetch the complete content index at: https://www.javahandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to install Maven
- URL: https://www.javahandbook.com/maven-course/how-to-install-maven/
- Published: 2025-08-09T03:12:58.000Z
- Updated: 2025-08-20T02:45:00.000Z
- Description: Learn how to install Apache Maven on Windows, macOS & Linux. Step-by-step guide covers downloading, setting JAVA_HOME/MAVEN_HOME environment variables & verifying installation with mvn -v command.
- Author: Gopi Gorantala
- Tags: Maven Fundamentals, #docs, #maven-course

## **Introduction**

Before you can use Apache Maven in your Java projects, you need to **install Maven** on your machine, configure the required environment variables, and verify the setup.

In this lesson, you’ll learn:

- How to install Maven on **Windows**, **macOS**, and **Linux**
- How to set up **JAVA\_HOME** and **MAVEN\_HOME** variables
- How to verify Maven installation using the `mvn -v` command

## **1\. Installing Maven on Windows**

**Step 1 – Download Maven**

1. Go to the official Apache Maven website:  
[https://maven.apache.org/download.cgi](https://maven.apache.org/download.cgi?ref=javahandbook.com)
2. Download the **binary zip archive** (e.g., `apache-maven-3.9.x-bin.zip`).

**Step 2 – Extract Maven**

1. Unzip the downloaded file.
2. Place the extracted folder (e.g., `apache-maven-3.9.x`) in a location like `C:\Program Files\Apache\Maven`.

**Step 3 – Set Environment Variables**

1. Open **Control Panel → System and Security → System → Advanced system settings**.
2. Click **Environment Variables**.
3. Add/Update:
  - **JAVA\_HOME** → Path to your JDK (e.g., `C:\Program Files\Java\jdk-17`)
  - **MAVEN\_HOME** → Path to Maven folder (e.g., `C:\Program Files\Apache\Maven\apache-maven-3.9.x`)
4. Update the `Path` variable to include:

```perl
%JAVA_HOME%\bin
%MAVEN_HOME%\bin

```

## **2\. Installing Maven on macOS**

**Option 1 – Install with Homebrew (Recommended)**

If you use Homebrew:

```bash
brew install maven
```

**Option 2 – Manual Installation**

- Download the binary tar.gz archive from Maven Downloads.
- Extract it to a directory (e.g., `/usr/local/apache-maven`).
- Add to your shell config (`.zshrc` or `.bash_profile`):

```bash
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
export M2_HOME=/usr/local/apache-maven/apache-maven-3.9.x
export PATH=$M2_HOME/bin:$PATH

```

- Save the file and run:

```bash
source ~/.zshrc

```

## **3\. Installing Maven on Linux**

**Option 1 – Install via Package Manager**

For Ubuntu/Debian:

```bash
sudo apt update
sudo apt install maven

```

For CentOS/Fedora:

```bash
sudo dnf install maven

```

**Option 2 – Manual Installation**

- Download the tar.gz from Maven Downloads.
- Extract it:

```bash
tar -xvzf apache-maven-3.9.x-bin.tar.gz -C /opt

```

- Set environment variables in `~/.bashrc` or `~/.zshrc` :

```bash
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
export M2_HOME=/opt/apache-maven-3.9.x
export PATH=$M2_HOME/bin:$PATH

```

- Apply changes:

```bash
source ~/.bashrc

```

---

## **4\. Setting JAVA\_HOME and MAVEN\_HOME (All OS)**

- **JAVA\_HOME** → Points to your Java Development Kit installation
- **MAVEN\_HOME** → Points to your Maven installation directory
- **PATH** → Should include `$JAVA_HOME/bin` and `$MAVEN_HOME/bin` so you can run `java`, `javac`, and `mvn` from any terminal or command prompt

Example (cross-platform shell syntax):

```bash
export JAVA_HOME=/path/to/jdk
export M2_HOME=/path/to/apache-maven
export PATH=$JAVA_HOME/bin:$M2_HOME/bin:$PATH

```

---

## **5\. Verifying Maven Installation**

Once installed and environment variables are set, check Maven’s version:

```bash
mvn -v

```

**Expected Output Example:**

```bash
Apache Maven 3.9.x (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.9.x
Java version: 17.0.8, vendor: Eclipse Adoptium
Default locale: en_US, platform encoding: UTF-8
OS name: Mac OS X, version: 13.5.1, arch: x86_64
```

If you see the Maven version, Java version, and OS details, your installation is successful.

## **Troubleshooting Tips**

- **Command not found:** Ensure Maven’s `bin` directory is in your PATH.
- **Wrong Java version:** Update JAVA\_HOME to point to the correct JDK.
- **Permission denied:** Use `sudo` (Linux/macOS) or run as administrator (Windows) for installation.

## **Key Takeaways**

- Maven requires **Java** to be installed first.
- Correctly setting **JAVA\_HOME** and **MAVEN\_HOME** is critical.
- The `mvn -v` command is the quickest way to verify a successful Maven installation.