How to install Maven on MacOS

234 阅读1分钟

Download

Download from here: maven.apache.org/download.cg…
Or click the link to download apache-maven-3.8.7-bin.tar.gz

Setup

  1. Have a JDK installation on your system. Either set the JAVA_HOME environment variable pointing to your JDK installation or have the java executable on your PATH.

  2. Extract distribution archive in any directory

    tar xzvf apache-maven-3.8.7-bin.tar.gz
    
  3. Add the bin directory of the created directory apache-maven-3.8.7 to the PATH environment variable

    1. In the terminal window, type the following command and press "enter":
    echo "export PATH=$PATH:/path/to/apache-maven-3.8.7/bin" >> ~/.bash_profile
    

    Replace "/path/to/apache-maven-3.8.7/bin" with the actual path to the "bin" directory on your computer. For example, if the "bin" directory is located in the "/Applications/apache-maven-3.8.7" folder, you would use the following command:

    echo "export PATH=$PATH:/Applications/apache-maven-3.8.7/bin" >> ~/.bash_profile
    

    This will add the "bin" directory to the PATH environment variable for your user account.

    1. To apply the changes and make the updated PATH variable available in the current terminal session, type the following command and press "enter":
    source ~/.bash_profile
    
    1. To confirm that you add the 'bin' directory to the PATH environment variable successfully: In the terminal window, type the following command and press "enter": echo $PATH

    This will display the current value of the PATH environment variable. Look for the "bin" directory in the list of directories that is displayed. If the "bin" directory is included in the PATH, it means that it has been successfully added to the environment variable. In this case, you should see the following directory in the list:

    /Applications/apache-maven-3.8.7/bin
    

    If you do not see the "bin" directory in the list, it means that it has not been added to the PATH environment variable. In that case, you may need to check your previous steps to make sure that you have added the "bin" directory to the PATH correctly.

    After you have updated the PATH variable, you should be able to run the Apache Maven command-line tools from any directory on your computer.

  4. Confirm with mvn -v in a new shell. The result should look similar to

    Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
    
    Maven home: /Applications/apache-maven-3.8.7
    
    Java version: 1.8.0_45, vendor: Oracle Corporation
    
    Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
    
    Default locale: en_US, platform encoding: UTF-8
    
    OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"