我正在尝试按照这些说明通过终端安装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
你去哪儿找这个?
我正在尝试按照这些说明通过终端安装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
你去哪儿找这个?
当前回答
这招对我很管用:
$ 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/
其他回答
在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"
这招对我很管用:
$ 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/
打开TERMINAL窗口并检查是否已经安装了它。
类型:
$ mvn –version
你应该看到:
Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
Java version: 1.6.0_24, 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.6.7″, arch: “x86_64″, family: “mac”
如果你还没有安装Maven,那么下面是如何下载和安装Maven,并在Mac OS X上配置环境变量:
http://bitbybitblog.com/install-maven-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
只是一个简短的补充;如果您想在MacOS上使用Homebrew 1.5.2安装特定版本,可以通过以下方式安装:
酿造更新 酿造搜索专家
这将为您提供homebrew中可用的maven版本
Brew install maven@3.3
[如果您想安装maven 3.3。]