我正在尝试按照这些说明通过终端安装maven。

到目前为止我得到了这个:

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

你去哪儿找这个?


当前回答

或者,我建议为这些实用程序安装Homebrew。

然后使用以下命令安装Maven:

brew install maven

PS:如果你得到一个404错误,尝试做一个酿造更新之前

其他回答

在Mavericks(10.9)之前的OS X实际上内置了Maven 3。

如果你使用的是OS X Lion系统,默认情况下你不会安装java。单独运行java,它会提示你安装它。

假设条件满足,运行mvn -version并看到如下输出:

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"

两个方法

(use homebrew) Auto install: Command: brew install maven Pros and cons Pros: easy Cons: (probably) not latest version Manually install (for latest version): Pros and cons Pros: use your expected any (or latest) version Cons: need self to do it Steps download latest binary (apache-maven-3.6.3-bin.zip) version from Maven offical download uncompress it (apache-maven-3.6.3-bin.zip) and added maven path into environment variable PATH normally is edit and add: export PATH=/path_to_your_maven/apache-maven-3.6.3/bin:$PATH into your startup script( ~/.bashrc or ~/.zshrc etc.)

额外的注意

如何立即生效并检查安装是否正确?

A:

source ~/.bashrc
echo $PATH
which mvn
mvn --version

这里的输出:

➜  bin pwd
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin
➜  bin ll
total 64
-rw-r--r--@ 1 crifan  staff   228B 11  7 12:32 m2.conf
-rwxr-xr-x@ 1 crifan  staff   5.6K 11  7 12:32 mvn
-rw-r--r--@ 1 crifan  staff   6.2K 11  7 12:32 mvn.cmd
-rwxr-xr-x@ 1 crifan  staff   1.5K 11  7 12:32 mvnDebug
-rw-r--r--@ 1 crifan  staff   1.6K 11  7 12:32 mvnDebug.cmd
-rwxr-xr-x@ 1 crifan  staff   1.5K 11  7 12:32 mvnyjp
➜  bin vi ~/.bashrc
➜  bin source ~/.bashrc
➜  ~ echo $PATH
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin:xxx
➜  bin which mvn
/Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3/bin/mvn
➜  bin mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/crifan/dev/dev_tool/java/maven/apache-maven-3.6.3
Java version: 1.8.0_112, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"

详情请参考我的(中文)帖子:【已解决】Mac中安装Gradle

这个命令酿造安装maven30不适合我。正在抱怨缺少配方。但是下面的命令起作用了。我已经安装了maven-3.0.5。

brew install homebrew/versions/maven30

这是Mac OS X 10.9又名Mavericks。

如果您尝试过brew install maven,但发现缺少gcc编译器和一些其他依赖项,那么更简单的方法是安装sdkman 然后运行

SDK安装maven

(或参考最新的文档以获得正确的命令)

对于这项工作,sdkman可能资历过高,但如果您要处理多个版本的sdk,那么它通常是一个非常好的工具。

感谢Ammar为优秀的提示

这招对我很管用:

$ vim .bash_profile

出口JAVA_HOME = $ (/ usr / libexec / JAVA_HOME)

$ source .bash_profile

来源:http://www.mkyong.com/java/maven-java_home-is-not-defined-correctly-on-mac-osx/