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

其他回答

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

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

在使用brew或手动安装maven后,使用macOS Catalina并使用终端或iTerm来操作maven,您将需要授予应用程序访问权限以访问用户文件。

系统首选项->隐私(按钮)->全磁盘访问

然后将terminal或iTerm添加到该列表中。

你还需要重新启动你的应用程序,例如终端或iTerm,在给他们完全的磁盘访问权限后。

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

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

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

Using Homebrew: you@host:~$ brew install maven will install latest Maven (3.5.2 on 02/01/2018) you@host:~$ brew install maven30 will install Maven 3.0 if needed Using Macports: (I did not test this) you@host:~$ sudo port install maven will install latest Maven (?) or: you@host:~$ sudo port install maven3 will Install Maven 3.0 you@host:~$ sudo port select --set maven maven3 selects that version of Maven Installing by hand: Download Maven from its homepage Follow the installation instructions: Extract the distribution archive, i.e.apache-maven-3.3.9-bin.tar.gz to the directory you wish to install Maven 3.3.9. The subdirectory apache-maven-3.3.9 will be created from the archive. 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. 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/bin is in your PATH environment variable (although that might not be necessary with the latest Mac OS X versions and the Oracle JDK). Add extracted apache-maven-3.3.9/bin to your $PATH Run mvn --version to verify that it is correctly installed.

在OS X上安装Maven,请到Apache Maven官网下载二进制压缩文件。

然后,您可以将下载文件夹中的apache-maven-3.0.5文件夹转移到您想要保存Maven的任何地方;然而,由于其余的过程涉及到命令行,我建议你从那里做所有的事情。

在命令行中,你可以运行如下代码:

mv ~/Downloads/apache-maven-3.0.5 ~/Development/

这只是我个人的偏好——在我的主目录中有一个“Development”目录。如果你愿意,你可以选择其他的。

接下来,编辑~/。在您选择的编辑器中配置文件,并添加以下内容:

export M2_HOME="/Users/johndoe/Development/apache-maven-3.0.5"
export PATH=${PATH}:${M2_HOME}/bin

第一行对Maven很重要(必须是一个完整的显式路径);为了运行“mvn”二进制文件,第二行对shell很重要。如果.profile中已经有第二行的变体,那么只需在它的末尾添加${M2_HOME}/bin。

现在打开第二个终端窗口并运行

mvn -version

输出应该是这样的…

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"

有几件事需要注意:

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) 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".

% sudo port selfupdate; 
% sudo port upgrade outdated;
% sudo port install maven3;
% sudo port select --set maven maven3;

— add following to .zshenv -- start using zsh if you dont —
set -a
[[ -d /opt/local/share/java/maven3 ]] &&
    M3_HOME=/opt/local/share/java/maven3 &&
    M2_HOME=/opt/local/share/java/maven3 &&
    MAVEN_OPTS="-Xmx1024m" &&
    M2=${M2_HOME}/bin
set +a