Apache Maven is an open-source, community-driven project that aims to build and maintain the most popular Open Source tools for building Java applications. It was created by the Apache Software Foundation in 2001 as an attempt to standardize the build process for Java projects. Over the years, it has developed into a robust set of tools that can be used for a wide range of projects.
Maven provides a number of benefits, including integration with other tools such as Jenkins, AWS CodeStar, and more. This allows for more automated builds and faster release cycles.
In this tutorial, we will discuss two methods of installing Maven on the macOS system.
- Method 1: Installing maven using homebrew
- Method 2: Installing maven manually
- Java Development Kit (JDK): Maven 3.3+ require JDK 1.7 or above to execute.
- Disk: Approximately 10MB is required for the Maven installation itself. In addition to that, additional disk space will be used for your local Maven repository.
- Operating System: No minimum requirement. Can be run on any operating system with JDK installed.
Method 1: Installing Maven on macOS using Homebrew
The latest Maven is available as Homebrew formulae. Use the following steps to install Maven on macOS along with a few other useful information.
- Make sure that the macOS system has Homebrew installed and up to date. The below command will show you the brew version.
If it is not installed, use next tutorial to install Homebrew on macOS.
- Next is to install Maven on macOS. Run the below command to install the available version of Apache Maven on your macOS PC.
brew install maven
- After the installation is finished successfully, You can find the installed Maven version using the below command:
- The Maven’s main configuration file is settings.xml. Homebrew places the this configuration file under the
/usr/local/opt/maven/libexec/confdirectory. You can see the file with the below command:
ls -la /usr/local/opt/maven/libexec/conftotal 32 drwxr-xr-x 5 admin admin 160 Jun 6 09:16 . drwxr-xr-x 6 admin admin 192 Jun 6 09:16 .. drwxr-xr-x 3 admin admin 96 Jun 6 09:16 logging -rw-r--r-- 1 admin admin 10742 Jun 6 09:16 settings.xml -rw-r--r-- 1 admin admin 3747 Jun 6 09:16 toolchains.xml
That’s it. You have successfully installed Apache Maven on your macOS system.
The below instructions will be useful to upgrade Maven or uninstall it from your system in the future.
- Upgrade Maven: Skip steps from here, if you have installed Maven right now. The below instructions will be helpful later to upgrade the Maven version. You can upgrade the Maven version anytime with this single command.
brew upgrade maven
brew uninstall maven
Method 2: Manually Install Maven on MacOS
We recommend using Homebrew to install Maven, which also provides the latest packages with easier upgrade options. But if want Maven to install for a specific user, then use the below instructions to install Maven manually on macOS>
- You can download the latest Apache Maven from its official download page.
- The downloaded file will be created under the ~/Downloads directory. Open a terminal and extract the downloaded archive file.
tar xzf ~/Downloads/apache-maven-3.8.6-bin.tar.gz -C ~
- The above command will extract the file under the home directory. You can check the files with the below command:
ls -la ~/apache-maven-3.8.6/total 64 drwxr-xr-x 9 admin staff 288 Sep 14 00:28 . drwxr-xr-x+ 20 admin staff 640 Sep 14 00:28 .. [email protected] 1 admin staff 17568 Jun 6 09:16 LICENSE [email protected] 1 admin staff 5141 Jun 6 09:16 NOTICE [email protected] 1 admin staff 2612 Jun 6 09:16 README.txt drwxr-xr-x 8 admin staff 256 Sep 14 00:28 bin [email protected] 4 admin staff 128 Jun 6 09:16 boot [email protected] 5 admin staff 160 Jun 6 09:16 conf [email protected] 61 admin staff 1952 Jun 6 09:16 lib
- macOS 10.5 Catalina or later uses the Zsh as the default shell. You can set the MVN_HOME and edit the PATH environment variable in
~/.zshrc. Edit the
~/.zshrcfile and update the following content.~/.zshrcexport MVN_HOME=~/apache-maven-3.8.6 export PATH=$MVN_HOME/bin:$PATH
The older macOS users edit the
~/.bash_profileand append the following content.~/.bash_profileexport MVN_HOME=~/apache-maven-3.8.6 export PATH=$MVN_HOME/bin:$PATH
To confirm which shell (Zsh or Bash) is active on your system, run the following command.
- You can simply restart your shell to apply changes or Use the below command to load the environment variables in the current shell.
Older macOS users change the above command to source
- That’s it. You have successfully installed Maven on your macOS system. Use the below command to check the installed Maven version:
mvn --versionOutput:Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /Users/admin/apache-maven-3.8.6 Java version: 220.127.116.11, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/18.104.22.168/libexec/openjdk.jdk/Contents/Home Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "12.5", arch: "x86_64", family: "mac"
Maven relies on defined dependencies between projects to keep everything consistent. This means that changes in one project won’t affect another unless explicitly stated. Maven can integrate with other tools such as Jenkins, AWS CodeStar, and more. This allows for more automated builds and faster release cycles. Maven centralizes all build information into one location, which makes it easy to track issues across teams.
The above instruction provides you details of Maven installation using Homebrew as well as installing Maven manually by downloading the binary source code.