获取 -bash: mvn: 命令未找到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1606174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 18:37:32  来源:igfitidea点击:

Getting -bash: mvn: command not found

bashmaven-2macos

提问by user170114

I tried setting the Maven PATH in .profile file as well using export commands in terminal(Mac OSX). But, on running mvn commands, getting -bash: mvn: command not found

我尝试在 .profile 文件中设置 Maven PATH 以及使用终端(Mac OSX)中的导出命令。但是,在运行 mvn 命令时,得到 -bash: mvn: command not found

Please help.

请帮忙。

回答by Pascal Thivent

What did you set up exactly? Did you setup PATH like this (or something equivalent):

你具体是怎么设置的?您是否像这样设置了 PATH(或类似的东西):

export PATH=$PATH:...:$M2_HOME/bin

If yes, did you logout and login again? According to the bash manpage:

如果是,您是否注销并重新登录?根据 bash 联机帮助页:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --loginoption, 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 --noprofileoption may be used when the shell is started to inhibit this behavior.
...
When an interactive shell that is not a login shellis started, bash reads and executes commands from /etc/bash.bashrcand ~/.bashrc, if these files exist. This may be inhibited by using the --norcoption. The --rcfilefile option will force bash to read and execute commands from file instead of /etc/bash.bashrcand ~/.bashrc.

当 bash 作为交互式登录 shell或带有--login选项的非交互式 shell调用时 ,它首先从文件中读取并执行命令/etc/profile(如果该文件存在)。读取该文件后,它会按该顺序查找~/.bash_profile~/.bash_login、 和~/.profile,并从第一个存在且可读的命令中读取和执行命令。--noprofile当 shell 启动时可以使用该选项来禁止这种行为。
...
当一个不是登录 shell的交互式 shell启动时,bash 读取并执行来自/etc/bash.bashrc和 的命令 ~/.bashrc(如果这些文件存在)。这可以通过使用--norc选项来禁止。这--rcfilefile 选项将强制 bash 从 file 而不是/etc/bash.bashrcand 读取和执行命令~/.bashrc

As you can see, commands from .profileare not executed for a non-login shell (the type of shells you open after logging in). So you have to logout/login or to source the file manually to take your setup into account. See this blog postfor more details.

如您所见,来自.profile非登录 shell(登录后打开的 shell 类型)的命令不会执行。因此,您必须注销/登录或手动获取文件以将您的设置考虑在内。有关更多详细信息,请参阅此博客文章

回答by Michael Aaron Safyan

Have you installed Maven, already? If you use MacPortsto install Maven, you won't need to edit your PATH.

你已经安装了Maven吗?如果您使用MacPorts安装 Maven,则无需编辑 PATH。