Apache maven installation is really simple. You just need to make sure that JDK is installed and JAVA_HOME
is configured correctly. All you do is unzip the maven zip/tar file and apache-maven-3.6.1/bin
PATH
Prerequisite
- Make sure JDK is installed in your system by running
java -version
in the terminal or command prompt. - If JDK is not installed yet, download it from the oracle site and follow the instructions to install it.
1. Install maven on Windows
- Set an environment variable
JAVA_HOME
to JDK installation path. I am using JDK 8, soJAVA_HOME
is pointing toC:\Program Files\Java\jdk1.8.0_172
. - Download the latest maven binary zip from Apache Maven site. When I created this tutorial, the latest version was
apache-maven-3.6.1-bin.zip
- Unzip the archive and move it to Program Files. In my case,
C:\Program Files\apache-maven\maven-3.6.1
- Set the environment variables
M2_HOME
andM2
using system properties for maven.M2_HOME=C:\Program Files\apache-maven\maven-3.6.1
M2=%M2_HOME%\bin
- Verify maven installation now by typing
mvn --version
in the command prompt.
2. Install maven on Mac
- Make sure JDK is installed. I advise making use of brew cask for mac. Install brew in Mac and then install cask if not installed. Now, you can install JDK by running
brew cask install java8
for jdk8 or for the latest version of JDK. - Once JDK is installed, you can use
brew search maven
to find the latest version of available maven and then install the right version using brew install, for examplebrew install [email protected]
will install maven-3.5. - Now type
mvn -v
to verify that the installation was successful.
Alternatively, you can also download the binary zip or tar from official maven site, extract them, move it to a correct directory and then add /bin
to the PATH.
3. Install maven on Linux
- I am assuming JDK is installed correctly in your LINUX.
- You can use
wget
or visit the link from a browser to download the binary tar file. Download the binaryapache-maven-3.6.1-bin.tar.gz
file from Maven site to/tmp/
folder. There may be a different version there, but the steps are the same. - Navigate to the folder where you want to install. I prefer installing in
/opt/
, so runcd /opt/
in the terminal. - Now extract the archive using
sudo tar -xvzf /tmp/apache-maven-3.6.1-bin.tar.gz
. This will extract and move the content to/opt/apache-maven-3.6.1/bin
- Set M2_HOME and PATH to maven bin by modifying the
/etc/environment
file. Use the below code as an example, you can usenano
orvi
text editors. Make sure you do not change any existing values, you only append:/opt/apache-maven-3.6.1/bin
for PATH andM2_HOME="/opt/apache-maven-3.6.1"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-1.8.0_172/bin:/opt/apache-maven-3.6.1/bin" JAVA_HOME="/usr/lib/jvm/jdk-1.8.0_172" M2_HOME="/opt/apache-maven-3.6.1"
- After making changes in the environment file, update the maven command
sudo update-alternatives --install "/usr/bin/mvn" "mvn" "/opt/apache-maven-3.6.1/bin/mvn" 0 sudo update-alternatives --set mvn /opt/apache-maven-3.6.1/bin/mvn
- Now, you need to verify that the installation was successful by running
mvn -v
in the terminal.
Maven bash auto-completion
Once you complete apache maven installation, if you like bash auto-completion feature, check out the maven bash auto-completion project on GitHub.