This is installation guide on How to install Maven in Mac OSX using Home Brew and from Mac’s Command Line Terminal.
Some of the Mac OS X versions comes with Maven 3 built in, installation located at /usr/share/maven
. To test Maven installed or not in your Mac issue command mvn -v
in Terminal, it shows you installed version if already installed otherwise error.
Before Maven setup make sure already Java JDK or GraalVM setup done on your Mac Machine.
1. Install Maven using brew on Mac
1. The simplest way to install Maven on your Mac OS is using brew command (brew install maven), if already Homebrew installed on your machine. Check if Homebrew installation using brew -v, you will get version if installed, otherwise you get ‘command not found’.
$ brew -v Homebrew 2.6.2 Homebrew/homebrew-core (git revision 4eef6; last commit 2020-12-20)
2. If not installed, issue following command in your terminal to quickly install Homebrew on your Mac OS.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
3. To Install Maven using brew on Mac, issue following command.
$ brew install maven
4. If everything goes fine, you will see following lines in terminal.
==> Downloading https://www.apache.org/dyn/closer.lua?path=maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz ==> Downloading from https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz ######################################################################## 100.0% ==> Installing maven 🍺 /usr/local/Cellar/maven/3.6.3_1: 87 files, 10.7MB, built in 14 seconds
5. Finally set Maven paths using following commands.
echo 'export MAVEN_HOME=/usr/local/Cellar/maven/3.6.3_1' >> ~/.bash_profile echo 'export PATH=$MAVEN_HOME/bin:$PATH' >> ~/.bash_profile
6. Test the installation using mvn -v
.
$ mvn -v Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec Java version: 11.0.7, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.1.0/Contents/Home Default locale: en_MY, platform encoding: UTF-8 OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"
2. Install Maven using Terminal on Mac
1. Download Maven and extract in Local Mac
Download binary tar archive from apache-maven-3.xxx-bin.tar.gz, extract it in your local system. In my case binary downloaded /Downloads/apache-maven-3.6.3-bin.tar.gz . Extract the archive file to specific location.
$ tar -xvf ~/Downloads/apache-maven-3.6.3-bin.tar.gz -C ~/Downloads/
Move to specific folder.
$ sudo mv ~/Downloads/apache-maven-3.6.3 /Library/apache-maven-3.6.3
2. Set MAVEN_HOME and $MAVEN_HOME/bin to PATH on Mac
Open .bash_profile using TextEdit or nano and include MAVEN_HOME and $MAVEN_HOME/bin to PATH.
sudo open -a TextEdit .bash_profile OR sudo nano .bash_profile
Add the following lines and save .bash_profile
file.
export MAVEN_HOME=/Library/apache-maven-3.6.3 export PATH=$MAVEN_HOME/bin:$PATH
Refresh the settings from .bash_profile
.
$ source .bash_profile
3. Test Maven Installation on Mac
Maven setup is done on Mac OS, to test the setup run mvn -version
or mvn -v
command.
3. Conclusion
In this guide we have seen how to install Maven on Mac operating system using brew and from Terminal Command line. Did it work for you or any issue comment below.
Other Maven Setups:
- Install Maven on Windows
- Install Maven on Ubuntu
- Import maven project into Eclipse
- Maven Skip Tests
- Maven Run Tests
- Maven set java version
- Maven run java main class
I get .bash_profile does not exist. Help.
in case .bash_profile does not exist. Create for first time.
touch ~/.bash_profile