In this tutorial, we will be going through the installation process of Maven.
If you are a WINDOWS user (if you are not, scroll down to view how to install Maven if you are a Linux or Mac user):
Before proceeding with the next steps, make sure you have JDK installed on your system. If you don’t, you can view this article for a quick step-by-step guide. To view all the necessary minimum requirements for Maven, either click here or view the image below
Click here and download the latest version. You can either select the Binary version or the full version (a.k.a. with source and docs). I recommend downloading the Binary one as you can find all the source and docs online anyway.
After your download is complete, extract the archive to C and preferably, create a folder in C named Maven and extract the files into there.
After you have created the Maven folder, extract the files from the downloaded zip file into that folder.
Now we have to set up M2_HOME. Before being able to run Maven, we need to set it in the environment variables and add the “bin” to PATH.
- Right-click somewhere on This PC
- Select Properties
- On the right, select Advanced System Settings
- After that, click on “Environmental Variables…”
- Under “System variables” select New…
- When the input box opens, type M2_HOME as a variable name and the path to the maven
- Under System variables, select “Path” and click on Edit…
- Add the path “C:\Maven\apache-maven-3.6.1\bin”
Verifying if the installation has been successful
To know if the installation has been successful for you, type this in the CMD:
If you get something like:
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-04T20:00:29+01:00) Maven home: C:\Maven\apache-maven-3.6.1\bin\.. Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_211\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
then you are good to go.
- Download apache-maven-3.6.1-bin.tar.gz binary (if you do not want the source and docs included).
cd /optin the terminal
- extract the apache-maven archive into the opt directory:
sudo tar -xvzf ~/Downloads/apache-maven-3.6.0-bin.tar.gz
- Add as environment variable:
and append the bin directory to the Path variable:
- Update the mvn command:
sudo update-alternatives --install "/usr/bin/mvn" "mvn" "/opt/apache-maven-3.6.0/bin/mvn" 0
sudo update-alternatives --set mvn /opt/apache-maven-3.6.0/bin/mvn
- Add bash completion to mvn:
sudo wget https://raw.github.com/dimaj/maven-bash-completion/master/bash_completion.bash --output-document /etc/bash_completion.d/mvn. This will allow you to complete Maven commands by hitting Tab a couple of times.
- Type mvn –version to verify if it works
- Open the terminal and go to the directory in which the files were extracted and login as Super User
- Remove the tar.gz archive by typing rm Downloads/apache-maven*bin.tar.gz
- Fix the permissions: chown -R root:wheel Downloads/apache-maven*
- Switch the maven contents: mv Downloads/apache-maven* /opt/apache-maven
- Archive the Admin session: exit
- Add Maven binaries to the path and then append:
- nano $HOME/.profile
- export PATH=$PATH:/opt/apache-maven/bin
- Ctrl + x to Save and Exit from nano
- To load the new set up execute bash
- To test if the installation has been successful, type mvn -version