Maven Install on Mac OS X

2019-01-05 06:39发布

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
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
export JAVA_HOME=/usr/java/jdk1.6.0_22

This is probably a stupid question where do you go to find this?

18条回答
Deceive 欺骗
2楼-- · 2019-01-05 07:36

macOS Sierra onwards

brew install maven

查看更多
别忘想泡老子
3楼-- · 2019-01-05 07:36

On Maverick, run in the terminal xcode-select --install to install the Command Line Tools.

查看更多
贪生不怕死
4楼-- · 2019-01-05 07:37

If using MacPorts on OS X 10.9 Mavericks, you can simply do:

sudo port install maven3
sudo port select --set maven maven3
查看更多
姐就是有狂的资本
5楼-- · 2019-01-05 07:38

Disclaimer: Here is a complete answer taking the last version of OS X (10.9 AKA Mavericks) into account. I am aware that everything I compiled in this answer is already present in the page, but having it clearly in one answer makes it a lot clearer.

First of all, with previous versions of OS X, Maven is installed by default. If Java is missing running you@host:~ $ java in a terminal will prompt you for the Java installation.

With Mac OS X 10.9 (Mavericks), Maven is not installed by default anymore. Different options are then possible:

  • Using Homebrew:
    • you@host:~$ brew install maven will install latest Maven (3.5.2 on 02/01/2018)
    • you@host:~$ brew install maven30 will install Maven 3.0 if needed
  • Using Macports: (I did not test this)
    • you@host:~$ sudo port install maven will install latest Maven (?)
    • or:
    • you@host:~$ sudo port install maven3 will Install Maven 3.0
    • you@host:~$ sudo port select --set maven maven3 selects that version of Maven
  • Installing by hand:
    • Download Maven from its homepage
    • Follow the installation instructions:
      1. Extract the distribution archive, i.e.apache-maven-3.3.9-bin.tar.gz to the directory you wish to install Maven 3.3.9. The subdirectory apache-maven-3.3.9 will be created from the archive.
      2. Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.
      3. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) and that $JAVA_HOME/bin is in your PATH environment variable (although that might not be necessary with the latest Mac OS X versions and the Oracle JDK).
      4. Add extracted apache-maven-3.3.9/bin to your $PATH
      5. Run mvn --version to verify that it is correctly installed.
查看更多
再贱就再见
6楼-- · 2019-01-05 07:38

When I upgraded recently to OS X Mavericks and my maven builds start failing. So I needed to install maven again as it doesn't come built in. Then I tried with the command:

brew install maven 

it works, but it installs the version 3.1.1 of maven which causes some problems for a few users like (https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound). So if you're running into the same issue you will probably want to install the earlier Maven version, the 3.0.5. To do that with Homebrew, you have to execute the following command:

brew install https://raw.github.com/Homebrew/homebrew-versions/master/maven30.rb

That's it, it will then use a different Homebrew's formulae which will give you the maven 3.0.5 instead.

查看更多
Emotional °昔
7楼-- · 2019-01-05 07:38

A simple approach to install Maven.

1. Open Terminal

Finder -> Go -> Utilities -> Terminal

2. Install Homebrew using the below command

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

3. After that install maven 

brew install maven

查看更多
登录 后发表回答