Maven Install on Mac OS X

后端 未结 24 2012
野性不改
野性不改 2020-11-27 08:46

I\'m trying to install maven through the terminal by following these instructions.

So far I got this

export M2_HOME=/user/apple/apache-maven-3.0.3
ex         


        
相关标签:
24条回答
  • 2020-11-27 09:35

    To install Maven on OS X, go to the Apache Maven website and download the binary zip file.

    You can then shift the apache-maven-3.0.5 folder in your Downloads folder to wherever you want to keep Maven; however as the rest of the process involves the command line, I recommend you do everything from there.

    At the command line, you would run something like:

    mv ~/Downloads/apache-maven-3.0.5 ~/Development/
    

    This is just my personal preference - to have a "Development" directory in my home directory. You can choose something else if you wish.

    Next, edit ~/.profile in the editor of your choice, and add the following:

    export M2_HOME="/Users/johndoe/Development/apache-maven-3.0.5"
    export PATH=${PATH}:${M2_HOME}/bin
    

    The first line is important to Maven (and must be a full explcit path); the second line is important to the shell, in order to run the "mvn" binary. If you have a variation of that second line already in .profile, then simply add ${M2_HOME}/bin to the end of it.

    Now open a second terminal window and run

    mvn -version
    

    which should give output like...

    Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 13:51:28+0000)
    Maven home: /Users/johndoe/Development/apache-maven-3.0.5
    Java version: 1.7.0_40, vendor: Oracle Corporation
    Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre
    Default locale: en_US, platform encoding: UTF-8
    OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
    

    Couple of things to note:

    1. If you've installed the Oracle JDK 1.7, then you may find Maven reports JDK 1.6 in the above output. To solve this, add the following to your ~/.profile:

      export JAVA_HOME=$(/usr/libexec/java_home)

    2. As some have pointed out, Maven has historically been supplied either with OS X itself, or with the optional Command Line Tools for XCode. This may cease to be the case for future versions of OS X, and in fact OS X Mavericks does not include Maven. Personal opinion: This could be because they are still in beta, or it could be that Apple have taken a look at the latest Thoughtworks Technology Radar, and spotted that Maven has been moved to "Hold".

    0 讨论(0)
  • 2020-11-27 09:35
    1. Open terminal
    2. Just use brew command to install maven
    brew install maven
    
    1. After the download and install finished. Check for the maven version
    mvn -version
    

    Here you go !!! Now you have successfully installed maven on your mac os.

    0 讨论(0)
  • 2020-11-27 09:36

    for the ones that just migrated to mavericks - I used the *-ux solution;

    1. download maven from apache maven site
    2. put in /opt
    3. modified .bash_profile and added:

      alias mvn='/opt/apache-maven-3.1.1/bin/mvn'
      export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
      
    0 讨论(0)
  • 2020-11-27 09:37

    A simple approach to install Maven.

    1. Open Terminal

    Finder -> Go -> Utilities -> Terminal

    1. Install Homebrew using the below command

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    1. After that install maven

    brew install maven

    0 讨论(0)
  • 2020-11-27 09:37

    If you have tried brew install maven and were greeted with missing gcc compiler and some other dependencies, an easier approach is to install sdkman and then run

    sdk install maven

    (or refer to the latest documentation for the right command)

    sdkman is probably over-qualified for the job, but if you deal with multiple versions of SDKs, it's a pretty nice tool to have in general.

    Credits to Ammar for the excellent tip

    0 讨论(0)
  • 2020-11-27 09:38

    Alternatively, I recommend installing Homebrew for these kinds of utilities.

    Then you just install Maven using:

    brew install maven
    

    PS: If you got a 404 error, try doing a brew update just before

    0 讨论(0)
提交回复
热议问题