How to install Apache Maven on Windows?
Introduction
Apache Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software: first, it describes how software is built, and second, it describes its dependencies.
In this article, I will show you how to install Apache Maven on Microsoft Windows.
Prerequisites
- A system running Microsoft Windows.
- A Java development kit (JDK) installed on your system.
Making sure you have a JDK installed
To check if you have a JDK installed, open a command prompt (Win+R
, then type cmd
and hit enter) and type:
java -version
The command prompt should show you the version of the JDK if it is properly installed:
If you don't have a JDK installed, you can download it from Sun's website Oracle's website.
Downloading Apache Maven
Visit the official Apache Maven website and download the latest version of Maven for Windows.
You'll want the binary zip archive (apache-maven-3.9.7-bin.zip
at the time of writing).
Next, unzip the archive to a directory in your system.
Note that this is the final location of the Maven installation, so choose wisely.
In my case, I'll be extracting it to C:\java\
where I keep all of my Java-related software.
Let's now continue by adding the required environment variables so that we can use Maven from the command line.
Adding the required environment variables
Before we can use Maven from the command line, we need to add a couple of environment variables to the system.
Press the Win+R
key combination to open the Run dialog, then type sysdm.cpl
and hit enter.
Next, click on the Advanced tab and then on the Environment Variables button.
Adding the JAVA_HOME environment variable
In case you don't have a JAVA_HOME
environment variable, click on the New button under System variables and add the following:
- Variable name:
JAVA_HOME
- Variable value:
C:\j2sdk1.4.2_19
(or wherever your JDK installation directory)
Adding the MAVEN_HOME environment variable
Next, add a MAVEN_HOME
environment variable under System variables with the following values:
- Variable name:
MAVEN_HOME
- Variable value:
C:\java\apache-maven-2.0.8
(or wherever you extracted the Maven archive)
Adding the MAVEN_HOME\bin directory to the PATH environment variable
Finally, we need to add the %MAVEN_HOME%\bin
directory to the PATH
environment variable to be able to reach the mvn.exe
executable from the command line.
To do this, select the PATH
environment variable under System variables and click on the Edit button.
Add ;%MAVEN_HOME%\bin
to the end of the Variable value field:
Click on OK to close the dialog and then on OK again to close the Environment Variables dialog. You should now be able to use Maven from the command line.
Checking the Maven installation
Open a new command prompt (Win+R
, then type cmd
and hit enter) and type:
mvn -version
The command prompt should show you the version of Maven: