[英]$ mvn -v – command not found
I installed Maven on macOS 10.12.6.我在 macOS 10.12.6 上安装了 Maven。 Added environment to
.bash_profile
file:将环境添加到
.bash_profile
文件:
export PS1="\h --- \t *************************** \w $ "
export JAVA_HOME=$(/usr/libexec/java_home)
export MAVEN_HOME=/Users/{user}/Documents/Path/Maven/maven_3.3.9
export GRADLE_HOME=/Users/{user}/Documents/Path/Gradle/gradle_6.1.1
export PATH=$PATH:$MAVEN_HOME/bin
export PATH=$GRADLE_HOME/bin:$PATH
After that I save it and set source .bash_profile
command in Terminal.之后我保存它并在终端中设置
source .bash_profile
命令。 When I try in Terminal input mvn -v
command I see:当我尝试终端输入
mvn -v
命令时,我看到:
-bash: mvn: command not found
-bash: mvn: 命令未找到
When I input $MAVEN_HOME
I see:当我输入
$MAVEN_HOME
我看到:
: No such file or directory/Path/Maven/maven_3.3.9
: 没有那个文件或目录/Path/Maven/maven_3.3.9
If I use echo $MAVEN_HOME
command I see:如果我使用
echo $MAVEN_HOME
命令,我会看到:
/Users/{user}/Documents/Path/Maven/maven_3.3.9
/Users/{user}/Documents/Path/Maven/maven_3.3.9
If I input this mvn
I see:如果我输入这个
mvn
我会看到:
-bash: mvn: command not found
-bash: mvn: 命令未找到
JDK on Mac - $JAVA_HOME
command in Terminal: Mac 上的 JDK - 终端中的
$JAVA_HOME
命令:
-bash: /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home: is a directory
-bash: /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home: 是一个目录
Can you help me please to understand where I missed.你能帮我理解我错过的地方吗?
Thank you very much for your answers, I fixed my problem just like that:非常感谢您的回答,我就这样解决了我的问题:
export PATH=/Users/{user}/Documents/Path/Maven/maven_3.3.9/bin:$PATH
After that everything worked as expected.之后,一切都按预期进行。 If you think my method is not good, please tell me why?
如果你觉得我的方法不好,请告诉我为什么?
Since it is a maven 2+, export M2_HOME
(see " What is the difference between M2_HOME
and MAVEN_HOME
")既然是maven 2+,导出
M2_HOME
(参见《 M2_HOME
和MAVEN_HOME
什么区别》)
And double check what echo $PATH
returns after sourcing the .bashrc
.并在采购
.bashrc
后仔细检查 echo $PATH
返回的内容。
Make sure it:确保它:
$M2_HOME/bin
$M2_HOME/bin
ls $M2_HOME/bin
does exists. ls $M2_HOME/bin
确实存在。Check this检查这个
1) Review your path, I think you are missing '$' character right before {user} 1) 检查您的路径,我认为您在 {user} 之前缺少 '$' 字符
2) Review execution permission for 'maven_3.3.9/bin/mvn' 2) 查看'maven_3.3.9/bin/mvn'的执行权限
3) Make sure you are using Bash as Unix shell (and not zsh or another) 3) 确保你使用 Bash 作为 Unix shell(而不是 zsh 或其他)
echo $SHELL
# output should look like: '/bin/bash'
4) If you are using bash then add maven's ENV variables to the file ~/.bashrc (or ~/.zshrc if you are using zsh) 4) 如果您使用的是 bash,则将 maven 的 ENV 变量添加到文件 ~/.bashrc (或 ~/.zshrc 如果您使用的是 zsh)
5) 'source' your configuration 5)“来源”您的配置
source ~/.bashrc
Notes笔记
I recommend understand differences between .bashrc and .bash_profile : http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html我建议了解.bashrc和.bash_profile之间的差异: http : //www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
If you want to keep your configuration on .bash_profile then just rebooting your system should be enough (to start a login shell which load .bash_profile )如果您想将配置保留在.bash_profile 上,那么只需重新启动系统就足够了(启动加载.bash_profile的登录shell)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.