在 OSX Mavrerick 中找不到 mvn 命令 [英] mvn command not found in OSX Mavrerick
问题描述
在将其标记为重复之前,我浏览了这些帖子,但没有任何帮助.
Before marking this as duplicate, I went through these posts, but nothing helped.
有些是特定于 Windows 的,并没有帮助.Mac OS X 上的几个人提出了建议,我尝试过但没有帮助.
Some are specific to windows and did not help. A couple of them on Mac OS X gave suggestions, that I tried but did not help.
我尝试过的(这正是 Maven
建议的):
What I tried (this is exactly what Maven
suggests):
解压分发包,即apache-maven-3.1.1-bin.tar.gz到您希望安装 Maven 3.1.1 的目录.这些说明假设您选择了/usr/local/apache-maven.子目录apache-maven-3.1.1 将从存档中创建.在命令中终端,添加 M2_HOME 环境变量,例如出口M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1.添加 M2环境变量,例如导出 M2=$M2_HOME/bin.可选:添加MAVEN_OPTS 环境变量来指定 JVM 属性,例如出口MAVEN_OPTS=-Xms256m -Xmx512m".可以使用这个环境变量为 Maven 提供额外的选项.将 M2 环境变量添加到您的路径,例如导出路径=$M2:$PATH.确保 JAVA_HOME 设置为JDK 的位置,例如导出 JAVA_HOME=/usr/java/jdk1.5.0_02并且 $JAVA_HOME/bin 在您的 PATH 环境变量中.运行 mvn--version 以验证它是否已正确安装.
Extract the distribution archive, i.e. apache-maven-3.1.1-bin.tar.gz to the directory you wish to install Maven 3.1.1. These instructions assume you chose /usr/local/apache-maven. The subdirectory apache-maven-3.1.1 will be created from the archive. In a command terminal, add the M2_HOME environment variable, e.g. export M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1. Add the M2 environment variable, e.g. export M2=$M2_HOME/bin. 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. Add M2 environment variable to your path, e.g. export PATH=$M2:$PATH. Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02 and that $JAVA_HOME/bin is in your PATH environment variable. Run mvn --version to verify that it is correctly installed.
我在用于安装的 terminal
上看到,它工作正常.我没有这个问题.但是当我尝试使用新的 终端
时,我得到 command not found
.
I see that on the terminal
that I used for installation, it works fine. I do not have this issue. but when I tried on a new terminal
, I get command not found
.
我还在我的 .bashrc
中添加了 export PATH=$M2
,我做了 source
然后重新启动了终端,仍然没有帮助.
I also added export PATH=$M2
to my .bashrc
, I did source
and then restarted the terminal, still it did not help.
有人可以建议如何在终端的所有会话中使用它吗?
can someone suggest how to make it available in all sessions of terminal?
谢谢
推荐答案
如果这些可能有帮助,请尝试以下操作:
Try following these if these might help:
由于您的安装在您安装的终端上运行,因此您所做的所有 exports
都适用于 当前 bash 及其子进程
.但不会生成到新的终端
.
Since your installation works on the terminal you installed, all the exports
you did, work on the current bash and its child process
. but is not spawned to new terminals
.
env
变量将丢失;使用 .bash_profile
,你可以让它在所有会话中可用,因为当 bash
会话开始时,它运行"它的 .bashrc 和 .bash_profile
env
variables are lost if the session is closed; using .bash_profile
, you can make it available in all sessions, since when a bash
session starts, it 'runs' its .bashrc and .bash_profile
现在按照以下步骤操作,看看是否有帮助:
Now follow these steps and see if it helps:
输入
env |grep M2_HOME
在正在工作的终端上.这应该给出类似
type
env | grep M2_HOME
on the terminal that is working. This should give something like
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
输入env |grep JAVA_HOME
应该是这样的:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
现在您有了 M2_HOME
和 JAVA_HOME
的 PATH.
Now you have the PATH for M2_HOME
and JAVA_HOME
.
如果你只是执行 ls/usr/local/apache-maven/apache-maven-3.1.1/bin
,你会在那里看到 mvn
二进制文件.你现在要做的就是每次使用 PATH 指向这个位置.由于bash
在PATH
中提到的所有目录路径中搜索,它会找到mvn
.
If you just do ls /usr/local/apache-maven/apache-maven-3.1.1/bin
, you will see mvn
binary there.
All you have to do now is to point to this location everytime using PATH. since bash
searches in all the directory path mentioned in PATH
, it will find mvn
.
现在打开
.bash_profile
,如果没有就创建一个
vi ~/.bash_profile
vi ~/.bash_profile
添加以下内容:
#set JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
保存文件并输入
source ~/.bash_profile
.此步骤执行.bash_profile
文件中的命令,您现在可以开始了.
save the file and type
source ~/.bash_profile
. This steps executes the commands in the.bash_profile
file and you are good to go now.
打开一个新终端并输入应该可以工作的 mvn
.
open a new terminal and type mvn
that should work.
这篇关于在 OSX Mavrerick 中找不到 mvn 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!