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

Prerequisites

  • 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.

  1. Make sure that the macOS system has Homebrew installed and up to date. The below command will show you the brew version.
    brew --version 

    If it is not installed, use next tutorial to install Homebrew on macOS.

  2. 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 
  3. After the installation is finished successfully, You can find the installed Maven version using the below command:
    maven --version 

    How to Install Maven on macOS

  4. The Maven’s main configuration file is settings.xml. Homebrew places the this configuration file under the /usr/local/opt/maven/libexec/conf directory. You can see the file with the below command:
    ls -la /usr/local/opt/maven/libexec/conf total 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 

 

  • Delete Maven: If the Maven is no longer required, uninstall it with the following command.
    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>

  1. You can download the latest Apache Maven from its official download page.
    How to Install Maven on macOS
    Download latest Maven binary files
  2. 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 ~ 
  3. 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
  4. 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 ~/.zshrc file and update the following content.
    ~/.zshrc

    export MVN_HOME=~/apache-maven-3.8.6 export PATH=$MVN_HOME/bin:$PATH

    The older macOS users edit the ~/.bash_profile and append the following content.

    ~/.bash_profile

    export 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.

    echo $SHELL  /bin/zsh
  5. You can simply restart your shell to apply changes or Use the below command to load the environment variables in the current shell.
    source ~/.zshrc 

    Older macOS users change the above command to source ~/.bash_profile file.

  6. That’s it. You have successfully installed Maven on your macOS system. Use the below command to check the installed Maven version:
    mvn --version 
    Output:

    Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /Users/admin/apache-maven-3.8.6 Java version: 18.0.2.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/18.0.2.1/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”

Conclusion

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.