我正在尝试按照这些说明通过终端安装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

你去哪儿找这个?


当前回答

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

SDK安装maven

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

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

感谢Ammar为优秀的提示

其他回答

macOS Sierra以上

Brew安装专家

两个方法

(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

在马华力号上,在终点站跑 xcode-select——安装 安装命令行工具。

如果在OS X 10.9 Mavericks上使用MacPorts,你可以简单地做:

sudo port install maven3
sudo port select --set maven maven3

这对我很管用。它更简单、更干净。 打开Mac终端,输入:

export MAVEN_HOME=~/apache-maven-3.8.1
export PATH=$PATH:$MAVEN_HOME/bin

当你打字的时候

mvn -version

你得到一个输出:

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/nisha/apache-maven-3.8.1
Java version: 16.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "11.4", arch: "x86_64", family: "Mac"

**编辑补充:

当您关闭终端并再次打开时,您将得到mvn: command not found,您将不得不再次运行该命令。

参考这个帖子永久安装