How to install Maven

Downloading and Installing Maven

if you want to download Maven manually, download it from http://maven.apache.org/download.cgi

But you can download Maven programmatically as the following. So, run below script in your terminal.

wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

tar -xzvf apache-maven*bin.tar.gz

# Fix the permissions:
# chown -R root:wheel Downloads/apache-maven*

mkdir /usr/local/apache-maven

mv apache-maven* /usr/local/apache-maven

rm apache-maven*

Setting environment variables in zsh

If you are using zsh, then run the following script in your terminal.

nano ~/.zshrc

export M2_HOME=/usr/local/apache-maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

source ~/.zshrc

Setting environment variables in bash

nano ~/.bashrc

# add these three lines at the end of file and CTRL+X and Y and click enter :)

export M2_HOME=/usr/local/apache-maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

source ~/.bashrc

Check Maven Version

# Verify if Maven is running
mvn -version

Leave a Reply