本文翻译自:Maven Install on Mac OS X
I'm trying to install maven through the terminal by following these instructions . 我正在尝试按照以下说明通过终端安装Maven。
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? 这可能是一个愚蠢的问题,您在哪里可以找到它?
#1楼
参考:https://stackoom.com/question/b2H3/在Mac-OS-X上进行Maven安装
#2楼
Open a TERMINAL window and check if you have it already installed. 打开一个TERMINAL窗口,然后检查是否已安装。
Type: 类型:
$ mvn –version
And you should see: 而且您应该看到:
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”
If you don't have Maven installed already, then here is how to download and install maven, and configure environment variables on Mac OS X: http://bitbybitblog.com/install-maven-mac/ 如果尚未安装Maven,则下面是下载和安装Maven以及在Mac OS X上配置环境变量的方法: http : //bitbybitblog.com/install-maven-mac/
#3楼
Alternatively, I recommend installing Homebrew for these kinds of utilities. 另外,我建议为这些实用程序安装Homebrew 。
Then you just install Maven using: 然后,您只需使用以下命令安装Maven:
brew install maven
PS: If you got a 404 error, try doing a brew update
just before PS:如果遇到404错误,请尝试在之前进行brew update
#4楼
To install Maven on OS X, go to the Apache Maven website and download the binary zip file. 要在OS X上安装Maven,请访问Apache Maven网站并下载二进制zip文件。
You can then shift the apache-maven-3.0.5 folder in your Downloads folder to wherever you want to keep Maven; 然后,您可以将“下载”文件夹中的apache-maven-3.0.5文件夹移动到您想保留Maven的任何位置; however as the rest of the process involves the command line, I recommend you do everything from there. 但是,由于该过程的其余部分都涉及命令行,因此我建议您从那里开始。
At the command line, you would run something like: 在命令行中,您将运行以下命令:
mv ~/Downloads/apache-maven-3.0.5 ~/Development/
This is just my personal preference - to have a "Development" directory in my home directory. 这只是我个人的喜好-在我的主目录中有一个“开发”目录。 You can choose something else if you wish. 您可以根据需要选择其他内容。
Next, edit ~/.profile in the editor of your choice, and add the following: 接下来,在您选择的编辑器中编辑〜/ .profile,并添加以下内容:
export M2_HOME="/Users/johndoe/Development/apache-maven-3.0.5"
export PATH=${PATH}:${M2_HOME}/bin
The first line is important to Maven (and must be a full explcit path); 第一行对Maven很重要(并且必须是一条完整的明确路径); the second line is important to the shell, in order to run the "mvn" binary. 第二行对于shell很重要,以便运行“ mvn”二进制文件。 If you have a variation of that second line already in .profile, then simply add ${M2_HOME}/bin to the end of it. 如果.profile中已有第二行的变体,则只需在其末尾添加$ {M2_HOME} / bin。
Now open a second terminal window and run 现在打开第二个终端窗口并运行
mvn -version
which should give output like... 这应该给输出像...
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 13:51:28+0000)
Maven home: /Users/johndoe/Development/apache-maven-3.0.5
Java version: 1.7.0_40, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
Couple of things to note: 需要注意的几件事:
If you've installed the Oracle JDK 1.7, then you may find Maven reports JDK 1.6 in the above output. 如果安装了Oracle JDK 1.7,则在上面的输出中可能会发现Maven报告JDK 1.6。 To solve this, add the following to your ~/.profile: 要解决此问题,请将以下内容添加到您的〜/ .profile中:
export JAVA_HOME=$(/usr/libexec/java_home) 导出JAVA_HOME = $(/ usr / libexec / java_home)
As some have pointed out, Maven has historically been supplied either with OS X itself, or with the optional Command Line Tools for XCode. 正如某些人指出的那样,Maven历史上是随OS X本身提供的,或者随XCode的可选命令行工具一起提供的。 This may cease to be the case for future versions of OS X, and in fact OS X Mavericks does not include Maven. 对于将来的OS X版本,情况可能不再如此,实际上OS X Mavericks不包括Maven。 Personal opinion: This could be because they are still in beta, or it could be that Apple have taken a look at the latest Thoughtworks Technology Radar, and spotted that Maven has been moved to "Hold". 个人意见:这可能是因为它们仍处于测试阶段,或者可能是因为Apple已经研究了最新的Thoughtworks Technology Radar,并发现Maven已移至“持有”状态。
#5楼
for the ones that just migrated to mavericks - I used the *-ux solution; 对于刚刚迁移到特立独行的人-我使用了* -ux解决方案;
- download maven from apache maven site 从Apache Maven网站下载Maven
- put in /opt 放入/ opt
modified .bash_profile and added: 修改了.bash_profile并添加:
alias mvn='/opt/apache-maven-3.1.1/bin/mvn' export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
#6楼
When I upgraded recently to OS X Mavericks and my maven builds start failing. 当我最近升级到OS X Mavericks时,我的Maven构建开始失败。 So I needed to install maven again as it doesn't come built in. Then I tried with the command: 所以我需要再次安装maven,因为它没有内置。然后我尝试使用以下命令:
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 ). 它可以工作,但是会安装Maven 3.1.1版,这会给一些用户(例如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. 因此,如果遇到相同的问题,则可能需要安装早期的Maven版本3.0.5。 To do that with Homebrew, you have to execute the following command: 要使用Homebrew做到这一点,您必须执行以下命令:
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. 就是这样,然后它将使用其他的Homebrew公式,该公式将为您提供maven 3.0.5。