Before we install Maven, we need to have JDK installed. Check out the Java installation with the following command:
>javac -version
For Windows, open the command prompt, and for Linux/Mac OS, open the terminal and use the preceding command to see the version of the JDK that is installed.
If JDK is not installed, please refer to following link and install it:
http://www.oracle.com/technetwork/java/javase/index-137561.html
Once Java is in place, let's move towards Maven's installation.
Maven's installation is a simple two-step process:
M2_HOME
variablePATH
variableThe installation of Maven is just setting up Maven home in the extracted Maven folder. For ease, let's assume the maven3
folder resides in C:Program Files
. Now, set Maven home with the following command in the command prompt:
set M2_HOME="c:Program Filesmaven3apache-maven-3.2.1"
Update the PATH
variable as follows:
set PATH =%PATH%;%M2_HOME%in
Alternatively, the variables can be set permanently by navigating to Desktop | My Computer | Properties. Visit http://www.computerhope.com/issues/ch000549.htm for more information.
Let's assume the maven3
folder resides in the /opt
folder. As Mac OS does not have the /opt
folder, let's create a folder opt
in root, that is, /opt
. Now, let's assume we have maven3
, the extracted folder in it. Then, set the Maven home by issuing the following command via the terminal:
export M2_HOME=/opt/maven3/apache-maven-3.2.1
Add Maven to the PATH
variable as follows:
export PATH=${M2_HOME}/bin:${PATH}
To add it permanently, add it to the bash
file as follows:
cd $HOME vi .bash_profile
Add the preceding variable, that is, two lines to the file, save it, and execute the following command:
source .bash_profile
After performing the previous steps, its time to verify the installation of Maven. To verify the installation, perform the following:
mvn -version
mvn -version
It should show the corresponding version of Maven installed, as shown in the following screenshot:
3.22.74.160