macos 在 Mac OS X 上安装 Maven

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8826881/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:46:02  来源:igfitidea点击:

Maven Install on Mac OS X

macosmavenmaven-3

提问by Edgardo Roldan

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?

这可能是一个愚蠢的问题,你去哪里找到这个?

采纳答案by Michael

OS X prior to Mavericks (10.9) actually comes with Maven 3 built in.

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

If you're on OS X Lion, you won't have java installed by default. Just run javaby itself and it'll prompt you to install it.

如果您使用的是 OS X Lion,则默认情况下不会安装 java。只需java自行运行,它就会提示您安装它。

Assuming qualifications are met, run mvn -versionand see some output like this:

假设满足条件,运行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"

回答by brasskazoo

Alternatively, I recommend installing Homebrewfor 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 updatejust before

PS:如果您遇到 404 错误,请尝试在brew update之前执行

回答by snooze92

Disclaimer: Here is a complete answer taking the last version of OS X (10.9 AKA Mavericks) into account. I am aware that everything I compiled in this answer is already present in the page, but having it clearly in one answer makes it a lot clearer.

免责声明:这是考虑到最新版本的 OS X(10.9 AKA Mavericks)的完整答案。我知道我在这个答案中编译的所有内容都已经出现在页面中,但是在一个答案中清楚地说明它会更清晰。

First of all, with previous versions of OS X, Maven is installed by default. If Java is missing running you@host:~ $ javain a terminal will prompt you for the Java installation.

首先,对于以前的 OS X 版本,Maven 是默认安装的。如果you@host:~ $ java在终端中运行缺少 Java将提示您安装 Java。

With Mac OS X 10.9 (Mavericks), Maven is not installed by default anymore. Different options are then possible:

在 Mac OS X 10.9 (Mavericks) 中,Maven 不再默认安装。然后可以有不同的选择:

  • Using Homebrew:
    • you@host:~$ brew install mavenwill install latest Maven (3.5.2 on 02/01/2018)
    • you@host:~$ brew install maven30will install Maven 3.0 if needed
  • Using Macports: (I did not test this)
    • you@host:~$ sudo port install mavenwill install latest Maven (?)
    • or:
    • you@host:~$ sudo port install maven3will Install Maven 3.0
    • you@host:~$ sudo port select --set maven maven3selects that version of Maven
  • Installing by hand:
    • Download Maven from its homepage
    • Follow the installation instructions:
      1. Extract the distribution archive, i.e.apache-maven-3.3.9-bin.tar.gzto the directory you wish to install Maven 3.3.9. The subdirectory apache-maven-3.3.9will be created from the archive.
      2. Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.
      3. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)and that $JAVA_HOME/binis in your PATHenvironment variable (although that might not be necessary with the latest Mac OS X versions and the Oracle JDK).
      4. Add extracted apache-maven-3.3.9/binto your $PATH
      5. Run mvn --versionto verify that it is correctly installed.
  • 使用自制软件
    • you@host:~$ brew install maven将安装最新的 Maven (3.5.2 on 02/01/2018)
    • you@host:~$ brew install maven30如果需要,将安装 Maven 3.0
  • 使用Macports:(我没有测试这个)
    • you@host:~$ sudo port install maven将安装最新的 Maven (?)
    • 或者:
    • you@host:~$ sudo port install maven3将安装 Maven 3.0
    • you@host:~$ sudo port select --set maven maven3选择那个版本的 Maven
  • 手动安装:
    • 从其主页下载 Maven
    • 按照安装说明进行操作:
      1. 解压缩分发存档,即apache-maven-3.3.9-bin.tar.gz到您希望安装 Maven 3.3.9 的目录。apache-maven-3.3.9将从存档中创建子目录。
      2. 可选:添加 MAVEN_OPTS 环境变量以指定 JVM 属性,例如export MAVEN_OPTS="-Xms256m -Xmx512m". 此环境变量可用于为 Maven 提供额外的选项。
      3. 确保将 JAVA_HOME 设置为您的 JDK 的位置,例如export JAVA_HOME=$(/usr/libexec/java_home -v 1.8),它$JAVA_HOME/bin在您的PATH环境变量中(尽管对于最新的 Mac OS X 版本和 Oracle JDK,这可能不是必需的)。
      4. 添加提取apache-maven-3.3.9/bin到您的$PATH
      5. 运行mvn --version以验证它是否已正确安装。

回答by Alécio Carvalho

When I upgraded recently to OS X Mavericks and my maven builds start failing. So I needed to install maven again as it doesn't come built in. Then I tried with the command:

当我最近升级到 OS X Mavericks 并且我的 Maven 构建开始失败时。所以我需要再次安装 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). So if you're running into the same issue you will probably want to install the earlier Maven version, the 3.0.5. To do that with Homebrew, you have to execute the following command:

它可以工作,但它安装了 maven 3.1.1 版本,这会给一些用户带来一些问题,比如(https://cwiki.apache.org/confluence/display/MAVEN/AetherClassNotFound)。因此,如果您遇到同样的问题,您可能需要安装较早的 Maven 版本 3.0.5。要使用 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。

回答by Saorikido

macOS Sierra onwards

macOS Sierra 起

brew install maven

brew install maven

回答by Marc Smith

If using MacPortson OS X 10.9 Mavericks, you can simply do:

如果在 OS X 10.9 Mavericks 上使用MacPorts,您只需执行以下操作:

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

回答by RCross

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; however as the rest of the process involves the command line, I recommend you do everything from there.

然后,您可以将下载文件夹中的 apache-maven-3.0.5 文件夹移动到您想要保留 Maven 的任何位置;但是,由于该过程的其余部分涉及命令行,因此我建议您从那里开始执行所有操作。

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); the second line is important to the shell, in order to run the "mvn" binary. If you have a variation of that second line already in .profile, then simply add ${M2_HOME}/bin to the end of it.

第一行对 Maven 很重要(并且必须是完整的显式路径);第二行对 shell 很重要,以便运行“mvn”二进制文件。如果您在 .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:

需要注意的几点:

  1. If you've installed the Oracle JDK 1.7, then you may find Maven reports JDK 1.6 in the above output. To solve this, add the following to your ~/.profile:

    export JAVA_HOME=$(/usr/libexec/java_home)

  2. As some have pointed out, Maven has historically been supplied either with OS X itself, or with the optional Command Line Tools for XCode. This may cease to be the case for future versions of OS X, and in fact OS X Mavericks does not include 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".

  1. 如果您已经安装了 Oracle JDK 1.7,那么您可能会在上面的输出中找到 Maven 报告 JDK 1.6。要解决此问题,请将以下内容添加到您的 ~/.profile 中:

    导出 JAVA_HOME=$(/usr/libexec/java_home)

  2. 正如一些人指出的那样,Maven 历史上要么随 OS X 本身一起提供,要么随可选的 XCode 命令行工具一起提供。未来版本的 OS X 可能不再是这种情况,事实上 OS X Mavericks 不包括 Maven。个人意见:这可能是因为他们仍然处于测试阶段,或者可能是Apple查看了最新的Thoughtworks Technology Radar,并发现Maven已被移至“Hold”。

回答by Saurabh Padwekar

A simple approach to install Maven.

安装 Maven 的简单方法。

  1. Open Terminal
  1. 打开终端

Finder -> Go -> Utilities -> Terminal

Finder -> Go -> Utilities -> Terminal

  1. Install Homebrew using the below command
  1. 使用以下命令安装 Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. After that install maven
  1. 之后安装maven

brew install maven

brew安装maven

回答by zafar142003

Just a brief addition; if you want to install a specific version on MacOS using Homebrew 1.5.2, you can install it the following way:

只是一个简短的补充;如果要使用 Homebrew 1.5.2 在 MacOS 上安装特定版本,可以通过以下方式安装:

  1. brew update
  2. brew search maven
  1. 酿造更新
  2. 酿造搜索专家

This will give you maven versions available in homebrew

这将为您提供自制软件中可用的 Maven 版本

  1. brew install [email protected]
  1. brew 安装 [email protected]

[If you want to install maven 3.3.]

[如果要安装 maven 3.3。]

回答by edufinn

This command brew install maven30didn't work for me. Was complaining about a missing FORMULA. But the following command did work. I've got maven-3.0.5 installed.

这个命令brew install maven30对我不起作用。正在抱怨缺少 FORMULA。但是以下命令确实有效。我已经安装了 maven-3.0.5。

brew install homebrew/versions/maven30

This is for Mac OS X 10.9 aka Mavericks.

这适用于 Mac OS X 10.9 又名 Mavericks。