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
- Make sure JDK is installed in your system by running
java -versionin 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
to JDK installation path.I am using JDK 8, so
JAVA_HOMEis pointing to
- Download the latest maven binary zip from Apache Maven site. When I created this tutorial, the latest version was
- Unzip the archive and move it to Program Files. In my case,
- Set the environment variables
M2using system properties for maven.
- Verify maven installation now by typing
mvn --versionin 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 java8for jdk8 or for the latest version of JDK.
- Once JDK is installed, you can use
brew search mavento find the latest version of available maven and then install the right version using brew install, for example
brew install email@example.com install maven-3.5.
- Now type
mvn -vto 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
wgetor visit the link from a browser to download the binary tar file. Download the binary
apache-maven-3.6.1-bin.tar.gzfile 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 run
cd /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
- Set M2_HOME and PATH to maven bin by modifying the
/etc/environmentfile. Use the below code as an example, you can use
vitext editors. Make sure you do not change any existing values, you only append
:/opt/apache-maven-3.6.1/binfor PATH and
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 -vin 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.