我正在尝试按照这些说明通过终端安装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
你去哪儿找这个?
我正在尝试按照这些说明通过终端安装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
你去哪儿找这个?
当前回答
免责声明:这是一个完整的答案,考虑到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.
其他回答
对于那些想在Mavericks中使用maven2的人,输入:
酿造点击自制/版本
酿造安装maven2
如果您已经安装了maven3,请先在/usr/local/bin中备份3个链接(mvn, m2.conf, mvnDebug):
mkdir贝克
混合
然后重新安装:
Brew卸载maven2(仅当冲突时)
酿造安装maven2
当我最近升级到OS X Mavericks时,我的maven构建开始失败。所以我需要再次安装maven,因为它不是内置的。然后我试着输入命令:
brew install maven
它可以工作,但它安装了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
就是这样,它将使用不同的Homebrew公式,这将为您提供maven 3.0.5。
两个方法
(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
对于那些刚刚迁移到mavericks的-我使用*-ux解决方案;
从apache maven站点下载maven 输入/opt 修改了.bash_profile,新增: 别名mvn = ' / opt / apache-maven-3.1.1 / bin / mvn ' 出口JAVA_HOME = /图书馆/ Java / Home / JavaVirtualMachines / jdk1.7.0_21.jdk /内容
只是一个简短的补充;如果您想在MacOS上使用Homebrew 1.5.2安装特定版本,可以通过以下方式安装:
酿造更新 酿造搜索专家
这将为您提供homebrew中可用的maven版本
Brew install maven@3.3
[如果您想安装maven 3.3。]