How to install Maven on Windows 7,8 or 10?

There is no difference in installing Maven on Windows7, Windows 8, Windows 8.1 or Windows 10, you can follow the same steps to install Maven in any version Windows operating system. Installing Maven is very easy, just download the Apache Maven ZIP file from the Apache Maven Project website ( You can download the for using Maven in your 64-bit Windows machine. Remember, Maven 3.3 requires JDK 1.7 or above to run, so make sure you already installed JDK 7 or JDK8. Once you download the binary distribution of Maven, half of the job is down.

Now, you only need to extract the binary distribution and add the bin folder in PATH or add a couple of environment variable e.g. M2, M2_HOME into your Windows machine.

Btw, if you are just starting with Maven, I suggest you to first go through a comprehensive Maven course like Apache Maven: Beginner to Guru to learn some fundamentals. It will not only help you to build and deploy your Java and Spring Boot projects using Maven but also learn Maven itself in depth.

What you need to Install Maven in Windows

1) Make sure JDK is already installed. You need JDK 1.7 or above to run Maven 3.3. If you don't know how to install Java, see this guide for step by step tutorial.

2) Make sure that the JAVA_HOME environment variable is defined and should point to the installation directory of Java. Maven uses this environment variable to find the Java installation directory. See here to learn more about the JAVA_HOME environment variable.

Once you ensure that the above is in place, you need to follow the below steps to install Maven on your Windows machine.

1) Setup following environment variables
export M2_HOME=/Users/xxx/sdk/apache-maven-3.2.3
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xmx1048m -Xms256m -XX:MaxPermSize=312M"
export PATH=$M2:$PATH

I am using Cygwin that's why I am using the export command if you are using DOS command prompt then you should use the "set" command version shown below.

set M2_HOME=C:\\software\apache-maven-3.2.3
set M2=%M2_HOME%\bin
set MAVEN_OPTS="-Xmx1048m -Xms256m -XX:MaxPermSize=312M"
set PATH=%M2%;%PATH%

Though simply adding the bin directory of Maven installation folder to PATH is enough to run the "mvn" command, it's better to define well-known maven environment variables like M2_HOME and MAVEN_OPTS.

The M2_HOME is equivalent to JAVA_HOME and should point to the installation directory of Maven. On the other hand, MAVEN_OPTS is used by Maven script to fetch additional JVM arguments provided by the user. You can use this environment variable to increase the heap size of Maven by supplying JVM memory arguments e.g. -Xms and -Xmx. 

You can also read Maven Essentials to learn more about how Maven uses these environment variables.
How to install Maven on Windows 7 and 10

One you have to add bin directory of Maven folder, either directly or indirectly via an M2 environment variable, you should be able to run the mvn command from Cygwin or DOS command prompt. If Maven is setup correctly you will see similar output as shown below:

$ mvn -version
Apache Maven 3.2.3 
Maven home: C:\apache-maven-3.2.3
Java version: 1.6.0_37, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.6.0_37\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
You can see that it prints the Apache Maven version, along with Maven home, Java version, Java home and OS name.

At this point of time installation of Apache Maven is completed successfully and you are now ready to create and build Maven based Java project using different arch types. You can also use this locally installed Maven in eclipse instead of the default one installed by M2Eclipse plugin.

Further Learning
Maven Fundamentals by Bryan Hansen
Maven Crash Course
Java Maven :101 Stop Building Java Programs the Hard Way!


Anonymous said...

Why to bother installing Maven, when we can use newer technology - Gradle? IMO it's better and offer better tools and utilities for building applications.

Maven sounds so old and one idea better than Ant plus Ivy. What is the reason people still using it?

javin paul said...

Hello @Chris, I agree that Gradle is out there but many projects still uses Maven. It's more Maven than Gradle in professional world. If you don't know Maven, then you will struggle to work with team.

Post a Comment