sodcalculator

10 Tech How-To

Install Maven on Windows: Step-by-Step Guide

Guide 10-52921 · Updated · Step by step

To install Maven on Windows, you need to download the binary zip archive from the official Apache Maven website, extract it to a folder, and set two environment variables: MAVEN_HOME and PATH. After that, verify the installation by running mvn -version in a new Command Prompt. This guide walks through the entire process, including prerequisites, common pitfalls, and how to use Maven with popular IDEs.

What Is Maven and Why Use It?

Apache Maven is a build automation tool used primarily for Java projects. It manages dependencies (external libraries), compiles source code, runs tests, and packages the result into a JAR or WAR file. Instead of downloading JAR files manually and adding them to your classpath, Maven reads a pom.xml file that declares what your project needs, then downloads those libraries from a central repository and stores them locally. This makes builds reproducible: anyone with Maven and the same pom.xml can build the project identically.

Maven also enforces a standard project structure (e.g., src/main/java and src/test/java), which helps teams collaborate. While newer tools like Gradle offer more flexibility, Maven remains the most widely used build tool in the Java ecosystem, especially in enterprise environments.

Prerequisites: Java Is Required

Before installing Maven, you must have a Java Development Kit (JDK) installed. Maven itself is written in Java and needs a JRE (Java Runtime Environment) to run, but for building Java projects you need the full JDK. Check if Java is already installed by opening a Command Prompt and typing:

java -version

If the command is not recognized, download the latest JDK from a trusted source (e.g., Oracle or OpenJDK). Note that Maven 3.3+ requires Java 7 or higher, and Maven 3.9+ requires Java 8. For modern Spring Boot projects, Java 17 or 21 is common. After installing the JDK, set the JAVA_HOME environment variable to point to the JDK installation directory (e.g., C:\Program Files\Java\jdk-21) and add %JAVA_HOME%\bin to your PATH. Verify with java -version again.

Step-by-Step Installation

  1. Go to the official Apache Maven project website (maven.apache.org) and navigate to the Download section.
  2. Under “Files”, find the latest version and download the Binary zip archive (e.g., apache-maven-3.9.9-bin.zip). Avoid the source archive unless you plan to build Maven from source.
  3. Extract the downloaded ZIP file to a directory of your choice. A common location is C:\Program Files\Apache\maven or C:\maven. The extraction will create a folder like apache-maven-3.9.9. Avoid paths with spaces or special characters to prevent issues.
  4. Open the System Properties dialog (press Win + Pause, then click “Advanced system settings”, or search for “Edit the system environment variables” in the Start menu).
  5. Click Environment Variables. Under “System variables”, click New and create a variable named MAVEN_HOME with the value being the path to the Maven folder you just extracted (e.g., C:\maven\apache-maven-3.9.9).
  6. In the same dialog, find the Path variable, select it, and click Edit. Add a new entry: %MAVEN_HOME%\bin. Click OK on all dialogs.
  7. Open a new Command Prompt (important – not an existing one, because environment variable changes are not picked up by already-open windows). Type mvn -version and press Enter. You should see output showing Maven version, Java version, and the OS. If you see “mvn is not recognized”, re-check the Path variable and ensure you opened a new prompt.

Verifying the Installation

Running mvn -version is the standard verification. The output should look similar to:

Apache Maven 3.9.9 (8e9479b7b1b4d2d1d2d1d2d1d2d1d2d1d2d1d2d1d)
Maven home: C:\maven\apache-maven-3.9.9
Java version: 21.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-21
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

If you see this, Maven is installed and ready. If you get an error about JAVA_HOME not being set, go back and ensure the JAVA_HOME variable points to the JDK root (not the bin subfolder).

Common Installation Problems and Fixes

  • “mvn is not recognized as an internal or external command” – This means the PATH variable does not include %MAVEN_HOME%\bin. Double-check the entry, and make sure you open a new Command Prompt after editing.
  • “Error: JAVA_HOME is not defined correctly” – Maven cannot find Java. Verify that JAVA_HOME points to the JDK installation folder (e.g., C:\Program Files\Java\jdk-21), not to the bin subdirectory. Also ensure the path does not have a trailing backslash.
  • Maven works but downloads are slow or fail – This is usually a network or proxy issue. In a corporate environment, you may need to configure a proxy in the settings.xml file located in the conf folder of your Maven installation (or in ~/.m2).
  • Using an older version of Maven with a newer JDK – Some old Maven versions (e.g., 3.5 and earlier) may have compatibility issues with Java 17+. Always use the latest Maven release.

Using Maven with IDEs

Most Java IDEs (Eclipse, IntelliJ IDEA, NetBeans) have built-in Maven support. In IntelliJ IDEA, you can open a Maven project by selecting the pom.xml file. The IDE will use the Maven installation you configured, but you can also specify a different Maven home in the IDE settings. For example, in IntelliJ, go to Settings → Build, Execution, Deployment → Build Tools → Maven and set the “Maven home path” to your Maven directory. In Eclipse, you may need to install the M2E plugin (usually pre-installed in Eclipse IDE for Java Developers).

When you create a new Maven project from the command line using mvn archetype:generate, the IDE can import it. But many developers prefer to create the project directly in the IDE and then use the command line for builds, since the IDE and Maven share the same configuration.

Maven vs. Gradle: Which Should You Choose?

Gradle is another popular build tool that offers a more flexible and faster build process (via incremental builds and a daemon). It uses a Groovy or Kotlin DSL instead of XML. If you are starting a new project and have no constraints, Gradle is a strong choice, especially for Android development. However, Maven is still the default for many enterprise projects and has a larger repository of plugins. The good news: you can install both on the same machine without conflict. If you are learning Java, Maven is often recommended because its XML configuration is more explicit and easier to understand initially.

Frequently Asked Questions

Do I need to install Maven if I use IntelliJ IDEA?

No, IntelliJ IDEA bundles its own Maven distribution. You can use that directly without a separate installation. However, if you want to use Maven from the command line or ensure consistency across your team, installing Maven separately is recommended.

What is the difference between MAVEN_HOME and PATH?

MAVEN_HOME is a variable that points to the Maven installation directory. It is used by some scripts and tools to locate Maven. The PATH variable tells the operating system where to find executable files. Adding %MAVEN_HOME%\bin to PATH allows you to run mvn from any directory.

How do I update Maven on Windows?

To update, download the new binary ZIP, extract it to a new folder (or overwrite the old one), and update the MAVEN_HOME environment variable to point to the new folder. Then verify with mvn -version. There is no built-in update command.

Can I install Maven without admin rights?

Yes. You can extract Maven to a user folder (e.g., C:\Users\YourName\maven) and set user-level environment variables instead of system-level ones. The process is the same, but you edit the “User variables” section in the Environment Variables dialog.

Why does Maven download so many files on the first run?

Maven downloads plugins and dependencies from the central repository. The first build of a project downloads all required artifacts. After that, they are cached in the local repository (default: C:\Users\YourName\.m2\repository), so subsequent builds are faster.

Is Maven only for Java?

Maven is primarily designed for Java, but it can be used for other JVM languages like Kotlin and Scala, and even for non-JVM projects through plugins. However, its dependency management and build lifecycle are tightly coupled to the JVM ecosystem.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →