Java 如何在 OSX 10.10 (Yosemite) 上安装 Maven?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26812770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install Maven on OSX 10.10 (Yosemite)?
提问by Zach443
I am trying to install Maven on my Mac, but I can not get the JAVA_HOME variable right. The path that the maven website gives is,
我正在尝试在我的 Mac 上安装 Maven,但我无法正确获取 JAVA_HOME 变量。maven网站给出的路径是,
usr/java/jdk1.7.0_51
however the java folder does not exist in /usr/ for me. I installed the JRE and JDK, nothing changed. How can I fix this?
但是对我来说,/usr/ 中不存在 java 文件夹。我安装了 JRE 和 JDK,没有任何改变。我怎样才能解决这个问题?
采纳答案by mattias
Installing Maven (for me) usually involves these steps (apart from having a working java installed):
安装 Maven(对我来说)通常包括以下步骤(除了安装一个可用的 java):
- Download Maven from http://maven.apache.org/download.cgi
- Unpack to /path/to/maven
- 从http://maven.apache.org/download.cgi下载 Maven
- 解压到/path/to/maven
Set the following in .bashrc
在 .bashrc 中设置以下内容
export M2_HOME=/path/to/maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
Reload bash, and now "mvn --version" should be fine. Make sure to not have any reference to JAVA_HOME in your .bashrc (or .bash_aliases) if you havent already set it to somewhere you placed your jdk.
重新加载 bash,现在 "mvn --version" 应该没问题了。如果您尚未将 .bashrc(或 .bash_aliases)设置为放置 jdk 的位置,请确保在您的 .bashrc(或 .bash_aliases)中没有对 JAVA_HOME 的任何引用。
回答by hd1
On Yosemite, I've not had JAVA_HOME defined and I have version '1.7.0_65'. I also have maveninstalled and use it nearly every day. Installation of maven is performed by the following steps:
在优胜美地,我没有定义 JAVA_HOME 并且我有版本“1.7.0_65”。我也安装了maven,几乎每天都在使用它。maven的安装分为以下几步:
curl http://download.nextag.com/apache/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz | tar pzxvf -
- set the
MAVEN_HOME
environment variable to:
curl http://download.nextag.com/apache/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.tar.gz | tar pzxvf -
- 将
MAVEN_HOME
环境变量设置为:
pwd
/apache-maven-3.2.3
pwd
/apache-maven-3.2.3
- add MAVEN_HOME to your path.
- 将 MAVEN_HOME 添加到您的路径中。
Now you should be golden. Leave a comment if you aren't sorted.
现在你应该是金色的。如果您没有排序,请发表评论。
回答by Adam Lukaszczyk
Using brew - brew install maven
- that's it.
使用 brew - brew install maven
- 就是这样。
回答by Ruslan Zaytsev
In my case, none of the exported variables saved after bash quit. Also, export M2=$M2_HOME/bin; export PATH=$M2:$PATH
into bash didn't help, either. So, I had to write absolute paths into bash profile. Here are my steps:
就我而言,bash 退出后没有保存任何导出的变量。此外,export M2=$M2_HOME/bin; export PATH=$M2:$PATH
进入 bash 也无济于事。因此,我必须将绝对路径写入 bash 配置文件中。这是我的步骤:
1) open bash
1) 打开 bash
2) next two steps are required to correctly create paths in your system. Type in (line by line)
2) 需要接下来的两个步骤才能在您的系统中正确创建路径。输入(逐行)
JAVA_HOME=/usr/libexec/java_home
export M2_HOME=/path/to/your/apache-maven-3.x.x
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
3) than echo all four variables
3)比回显所有四个变量
echo $JAVA_HOME
echo $M2_HOME
echo $M2
echo $PATH
4) open second window of bash for your convenience.
4)为方便起见,打开bash的第二个窗口。
5) choose root folder (type cd without anything and press enter)
5)选择根文件夹(输入cd不带任何东西,然后按回车)
cd
6) if you don't have file called ?.bash_profile? than just create it
6) 如果您没有名为 ?.bash_profile 的文件?不仅仅是创建它
touch .bash_profile
7) open edit your ?.bash_profile?
7) 打开编辑你的 ?.bash_profile?
nano .bash_profile
5) copy results of echo commands to your ?.bash_profile?. it should look something like.
5) 将 echo 命令的结果复制到您的 ?.bash_profile? 中。它应该看起来像。
JAVA_HOME=/usr/libexec/java_home
M2_HOME=/path/to/your/apache-maven-3.x.x
M2=/path/to/your/apache-maven-3.x.x/bin
PATH=/path/to/your/apache-maven-3.x.x/bin:/path/to/maven/bin:/$….bla-bla-bla…
6) after edit save by pressing ctrl+s and close by ctrl+x
6) 编辑保存后按 ctrl+s 并按 ctrl+x 关闭
回答by logic-unit
回答by ranma2913
Sorry this is late.
对不起,这晚了。
I installed JDK and Maven following instructions from each of those sites, then I had to edit my .profile
file to get the PATH variables set.
我按照每个站点的说明安装了 JDK 和 Maven,然后我必须编辑我的.profile
文件以设置 PATH 变量。
$ sudo vim .profile
Then I added the following to my .profile (i
for insert mode)
然后我将以下内容添加到我的 .profile (i
用于插入模式)
# JDK configuration
#
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
#
# Maven configuration
#
MAVEN_3_3_3=/opt/maven/apache-maven-3.3.3
export MAVEN_3_3_3
M2_HOME=$MAVEN_3_3_3
export M2_HOME
PATH=$PATH:$M2_HOME/bin
export PATH
Next you write and quit vim (:wq
), quit and reopen terminal and type mvn --version
to test your install.
接下来,您编写并退出 vim ( :wq
),退出并重新打开终端并键入mvn --version
以测试您的安装。
Your output should look like this:
您的输出应如下所示:
$ mvn --version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T06:57:37-05:00)
Maven home: /opt/maven/apache-maven-3.3.3
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac"
Note:you may need to adjust the paths to your jdk and maven installations.
注意:您可能需要调整 jdk 和 maven 安装的路径。