Maven Install on Mac OS X

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?


OS X prior to Mavericks (10.9) actually comes with Maven 3 built in.

If you're on OS X Lion, you won't have java installed by default. Just run java by itself and it'll prompt you to install it.

Assuming qualifications are met, run mvn -version and see some output like this:

Apache Maven 3.0.3 (r1075438; 2011-02-28 12:31:09-0500)
Maven home: /usr/share/maven
Java version: 1.6.0_29, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.2", arch: "x86_64", family: "mac"

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


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:
  • Extract the distribution archive, ie 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.
  • Optional : Add the MAVEN_OPTS environment variable to specify JVM properties, eg export MAVEN_OPTS="-Xms256m -Xmx512m" . This environment variable can be used to supply extra options to Maven.
  • Make sure that JAVA_HOME is set to the location of your JDK, eg 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).
  • Add extracted apache-maven-3.3.9/bin to your $PATH
  • Run mvn --version to verify that it is correctly installed.
  • 链接地址: http://www.djcxy.com/p/53320.html

    上一篇: onInterceptTouchEvent()是否真的像sdk说的那样工作?

    下一篇: Maven在Mac OS X上安装