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

你去哪儿找这个?


当前回答

两个方法

(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

其他回答

免责声明:这是一个完整的答案,考虑到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.

这招对我很管用:

$ 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"

您可以使用Maven版本管理器,通过它可以在每个目录基础上使用多个版本的Maven。

安装

使用自制软件安装mvnvm

没有自制的mkdir -p ~/bin && curl -s https://bitbucket.org/mjensen/mvnvm/raw/master/mvn > ~/bin/mvn && chmod 0755 ~/bin/mvn,并添加~/bin到路径。

使用

默认的版本

要设置默认maven版本,请将环境变量DEFAULT_MVN_VERSION设置为默认使用的maven版本。

文件夹的Maven版本

创建名为mvnvm的文件。属性,并按如下方式配置maven版本

mvn_version = < maven版>

安装Maven的简单方法。

打开终端

Finder -> Go -> Utilities -> Terminal

使用下面的命令安装Homebrew

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

然后安装maven

Brew安装专家