> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/maven/installation.md).

# Installation

## About

Apache Maven is a build automation and project management tool primarily used for Java-based projects. This guide provides step-by-step instructions to install Maven on Windows and macOS systems.

## Prerequisites

Before installing Maven, ensure that the following prerequisites are met:

### Java Development Kit (JDK)

* Maven requires **Java JDK 8 or higher**.
* Ensure Java is installed and properly configured.

**To check if Java is installed**

Open a terminal or command prompt and run:

```bash
java -version
```

This should output the installed Java version.

**To check the JDK compiler**

```bash
javac -version
```

If not installed, download and install the JDK from:

* Oracle: <https://www.oracle.com/java/technologies/javase-downloads.html>
* OpenJDK: <https://jdk.java.net/>

#### JAVA\_HOME Environment Variable

Ensure the `JAVA_HOME` environment variable is set and points to our JDK installation directory.

## Downloading Apache Maven

1. Go to the official Maven download page: <https://maven.apache.org/download.cgi>
2. Download the **binary zip archive** (for Windows) or **tar.gz archive** (for macOS/Linux):
   * Example: `apache-maven-3.9.6-bin.zip` or `apache-maven-3.9.6-bin.tar.gz`
3. Verify the archive’s checksum (optional but recommended) using the instructions provided on the download page.

## Installation on Windows

### Step 1: Extract the Archive

* Extract the `.zip` file to a preferred location, such as:

  ```
  C:\Program Files\Apache\Maven
  ```

### Step 2: Set Environment Variables

Open System Properties > Environment Variables, and configure the following:

**Add `MAVEN_HOME`:**

* Variable Name: `MAVEN_HOME`
* Variable Value: path to your Maven folder, e.g.:

  ```
  C:\Program Files\Apache\Maven\apache-maven-3.9.6
  ```

**Add Maven `bin` directory to `Path`:**

* Edit the `Path` variable and add:

  ```
  %MAVEN_HOME%\bin
  ```

### Step 3: Verify Installation

Open a new Command Prompt and run:

```bash
mvn -version
```

We should see Maven version, Java version, and our operating system.

## Installation on macOS

### Option 1: Install via Homebrew (recommended)

If we have Homebrew installed:

```bash
brew install maven
```

This will automatically handle download, setup, and path configuration.

**To verify**

```bash
mvn -version
```

### Option 2: Manual Installation

**Step 1: Extract the Archive**

Download and extract the `tar.gz` archive:

```bash
tar -xvzf apache-maven-3.9.6-bin.tar.gz
sudo mv apache-maven-3.9.6 /opt/maven
```

**Step 2: Set Environment Variables**

Add the following to your `~/.bash_profile`, `~/.zshrc`, or `~/.bashrc` (depending on your shell):

```bash
export M2_HOME=/opt/maven
export PATH=$M2_HOME/bin:$PATH
```

Apply the changes:

```bash
source ~/.bash_profile
# or
source ~/.zshrc
```

**Step 3: Verify Installation**

```bash
mvn -version
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/maven/installation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
