我尝试在 .profile 文件中设置 Maven PATH,并在终端 (Mac OSX) 中使用导出命令。但是,在运行 mvn 命令时,得到 -bash: mvn: command not found
请帮忙。
最佳答案
你具体设置了什么?您是否像这样设置 PATH(或类似的东西):
export PATH=$PATH:...:$M2_HOME/bin
如果是,您是否注销并重新登录?根据 bash 联机帮助页:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the
--login
option, it first reads and executes commands from the file/etc/profile
, if that file exists. After reading that file, it looks for~/.bash_profile
,~/.bash_login
, and~/.profile
, in that order, and reads and executes commands from the first one that exists and is readable. The--noprofile
option may be used when the shell is started to inhibit this behavior.
...
When an interactive shell that is not a login shell is started, bash reads and executes commands from/etc/bash.bashrc
and~/.bashrc
, if these files exist. This may be inhibited by using the--norc
option. The--rcfile
file option will force bash to read and execute commands from file instead of/etc/bash.bashrc
and~/.bashrc
.
如您所见,.profile
中的命令不会针对非登录 shell(登录后打开的 shell 类型)执行。因此,您必须注销/登录或手动获取文件以考虑您的设置。看这个blog post更多细节。
关于bash - 获取-bash : mvn: command not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1606174/