Install Apache Maven

Download latest release of the software from Apache Maven Download Page.

Installing on Linux and Mac

Extract the downloaded zip file to some folder. For the sake of explanation, we use /opt/apache-maven directory as the maven home.

$ mkdir /opt/apache-maven
$ cd /opt/apache-maven
$ unzip apache-maven-3.3.1-bin.zip
$ ln -s apache-maven-3.3.1 maven

Next, set and export M2_HOME and PATH environment variables.

export M2_HOME=/opt/apache-maven/maven
export PATH=$M2_HOME/bin:${PATH}

To persist these variables across restarts, add the exports to $HOME/.bash_profile.

Installing on Windows

In Windows, extract the downloaded zip to c:Program Filesdirectory and then set environment variables.

C:Usersm > set M2_HOME=c:Program Filesapache-maven-3.3.1
C:Usersm > set PATH=%PATH%;%M2_HOME%bin

To make these environment variables persistence across restarts, add them to the System environment variables through the control panel. Go to Control Panel and select System. Go to Advanced tab and click Environment Variables. Use New to add M2_HOME variable. To modify the path, select Path from System Variables section and click Edit and add string %M2_HOME%bin; in the Variable value field to the front of the existing value and save changes.

Verify the setup

Verify the setup by running mvn -- version.

Install Apache Maven - verify setup

In case of error, check whether M2_HOME and PATH are set properly and Java executable is available in the path.

 
 

In the next chapter, we create a simple project and use Maven to build it.