[英]Command not found - Oh-My-Zsh
I recently installed zsh and oh-my-zsh in my Mac.我最近在我的 Mac 上安装了 zsh 和 oh-my-zsh。 Now when I try to run a maven command from the terminal, I am getting the following error.
现在,当我尝试从终端运行 maven 命令时,出现以下错误。
$ mvn install
zsh: command not found: mvn
I have installed Apache maven in /Applications directory.我已经在 /Applications 目录中安装了 Apache maven。 Currently my.zshrc file looks like below.
目前 my.zshrc 文件如下所示。
plugins=(git brew pip mvn mysql-macports python sublime tmux osx)
# ####################
# Maven Config Options
# ####################
export M2_HOME=/Applications/apache-maven-3.3.3
export PATH=$PATH:M2_HOME/bin
As seen above, I appended location of maven installation to the path.如上所示,我将 maven 安装位置附加到路径中。 But I am still getting errors.
但我仍然遇到错误。 Any help is appreciated.
任何帮助表示赞赏。
➜ ~ mvn
zsh: command not found: mvn
step 1:
vim ~/.zshrc
step 2:(Add at the end of the file)
source ~/.bash_profile;
step 3:(Execution shell)
> source ~/.bash_profile
➜ / mvn
[INFO] Scanning for projects...
.......
[INFO] Scanning for projects...
.......
Just add:只需添加:
source ~/.bash_profile
to .zshrc到 .zshrc
I had a similar problem after installing oh-my-zsh, but for adb command.安装 oh-my-zsh 后我遇到了类似的问题,但对于 adb 命令。 Looks like the
PATH
is shortened when oh-my-zsh is installed.安装 oh-my-zsh 后,
PATH
似乎缩短了。 I solved it using following steps.我使用以下步骤解决了它。
Open the .zshrc
file打开
.zshrc
文件
sudo nano ~/.zshrc
Look for # User configuration
查找
# User configuration
Un-comment the following line:取消注释以下行:
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
Save the file.保存文件。
source ~/.zshrc
Give this one a try for other similar command not found errors.试一试其他类似的命令未找到错误。
Try below steps:尝试以下步骤:
Open terminal and run command vi ~/.zshrc
打开终端并运行命令
vi ~/.zshrc
Add below lines in file:在文件中添加以下行:
export M2_HOME=/Users/<username>/Downloads/apache-maven-3.6.3
export PATH=${M2_HOME}/bin:${PATH}
export PATH
Save file successfully成功保存文件
Open another terminal instance & run command mvn -version
打开另一个终端实例并运行命令
mvn -version
It should work!它应该工作!
$
in PATH=$PATH:M2_HOME/bin
$
PATH=$PATH:M2_HOME/bin
中的 $source ~/.zshrc
to take the settings into effect instantly.source ~/.zshrc
以使设置立即生效。As mentioned by @4ae1e1 in his comment, $
have to be added before M2_HOME
while referring it in the PATH
variable, as follows:正如@4ae1e1在他的评论中提到的,
$
必须在M2_HOME
之前添加,同时在PATH
变量中引用它,如下所示:
export M2_HOME=/Applications/apache-maven-3.3.3
export PATH=$PATH:$M2_HOME/bin/
Once added, as others suggested, source the ~/.zshrc
file.添加后,如其他人建议的那样,获取
~/.zshrc
文件。
Step 1: open zshrc file第一步:打开zshrc文件
sudo nano ~/.zshrc
step 2: add 'mvn' in plugins section第 2 步:在插件部分添加“mvn”
plugins=(git zsh-autosuggestions mvn)
step 3: add maven configuration in zshrc file.第 3 步:在 zshrc 文件中添加 maven 配置。 ( make sure your apache maven extract directory. I have extracted in /opt folder )
(确保您的 apache maven 提取目录。我已在 /opt 文件夹中提取)
# Maven Config Options
export M2_HOME=/opt/apache-maven-3.8.4
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
step 4: save the chnages第 4 步:保存更改
ctrl+o
ENTER
ctrl+z
Step 5: reload zshrc file第 5 步:重新加载 zshrc 文件
source ~/.zshrc
Step 6: go to terminal and verify第6步:进入终端并验证
mvn -v
Output :输出 :
Apache Maven 3.8.4
Maven home: /opt/apache-maven-3.8.4
Java version: 11.0.11, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-
openjdk-amd64 Default locale: en_IN, platform encoding: UTF-8 OS name:
"linux", version: "5.4.0-89-generic", arch: "amd64", family: "unix"
I faced the exact same issue, this is what worked for me:我遇到了完全相同的问题,这对我有用:
sudo nano ~/.zshrc
add this:添加这个:
export PATH=your maven path/apache-maven-3.6.3/bin:/usr/bin:/bin:/usr/sbin:/sbin
Ctrl + X , select "Y", Press Enter Ctrl + X ,选择“Y”,回车
source ~/.zshrc
Validate: mvn -version
验证:
mvn -version
On macOS, you can add the following to your .zshrc file.在 macOS 上,您可以将以下内容添加到您的 .zshrc 文件中。
If you have not, download maven from https://maven.apache.org/download.cgi如果还没有,请从https://maven.apache.org/download.cgi下载 maven
# Maven
export PATH=/opt/apache-maven-3.8.3/bin:${PATH} # you could have it in a different directory
To edit .zshrc, you can use an existing text editor such as vim.要编辑 .zshrc,您可以使用现有的文本编辑器,例如 vim。
$ cd ~
$ vim .zshrc
Use i
to insert the export statements.使用
i
插入导出语句。 Once inserted, use esc
to exit insert mode.插入后,使用
esc
退出插入模式。 Then use :wq!
然后使用
:wq!
to save and quit the editor.保存并退出编辑器。 Finally, source the file to see the effects of your new changes.
最后,获取文件以查看新更改的效果。
$ source .zshrc
Now try mvn
and you should see something like this.现在试试
mvn
,你应该会看到类似这样的东西。
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.049 s
[INFO] Finished at: 2021-10-11T13:34:20-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
I think the answers above are too deep.我认为上面的答案太深了。 It could be that the person does not have Maven installed on their Local PC.
可能是该人没有在其本地 PC 上安装 Maven。 So please run the command below on your terminal
所以请在您的终端上运行以下命令
brew install maven
Afterwards on your IntelliJ or the terminal where the project is located run the command然后在您的 IntelliJ 或项目所在的终端上运行命令
mvn clean install
Use the command to double check if it was installed mvn --version
使用命令仔细检查是否已安装
mvn --version
vi ~/.zshrc
add source ~/.bash_profile
to ~/.zshrc file, after the line source $ZSH/oh-my-zsh.sh
将
source ~/.bash_profile
添加到 ~/.zshrc 文件中,在source $ZSH/oh-my-zsh.sh
行之后
open up a new terminal tab and execute mvn
, and it will start working.打开一个新的终端选项卡并执行
mvn
,它将开始工作。
I had the same issue.我遇到过同样的问题。 So created .zshrc file and added below in that file.
因此创建了 .zshrc 文件并在该文件下方添加。 export M2_HOME=/Users/gandharavmehra/Desktop/Development/Tools/apache-maven-3.6.3 export PATH=$PATH:$M2_HOME/bin
export M2_HOME=/Users/gandharavmehra/Desktop/Development/Tools/apache-maven-3.6.3 export PATH=$PATH:$M2_HOME/bin
after this gandharvmehra@MacBook-Pro ~ % source ~/.zshrc在此之后 gandharvmehra@MacBook-Pro ~ % source ~/.zshrc
close the Terminal and open again关闭终端并再次打开
gandharamehra@MacBook-Pro ~ % mvn -version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) gandharamehra@MacBook-Pro ~ % mvn -version Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
it should work 100 percent它应该 100% 有效
Combining other answers I got adb working on mac and zsh appending these two path lines to .zshrc:结合其他答案,我让 adb 在 mac 和 zsh 上工作,将这两条路径行附加到 .zshrc:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# this are for Android Studio adb:
export PATH=~/Android/sdk/tools:$PATH
export PATH=~/Android/sdk/platform-tools:$PATH
实际上, .bash_profile
用于/bin/bash
shell,对于您的/bin/zsh
shell,该文件称为.zprofile
,您应该在.zprofile
中执行与.bash_profile
中相同的操作
I have similar issue today with mvn command not found我今天有类似的问题,找不到 mvn 命令
In my example problem was with incorrect path - I missed one / at the beginning of the path在我的示例中,问题是路径不正确 - 我在路径的开头错过了一个 /
If you are running Catalina you will face this problem often.如果你正在运行 Catalina,你会经常遇到这个问题。
I found this Video very helpful to solve related problems.我发现这个视频对解决相关问题很有帮助。
You wouldn't happen to be on IntelliJ would you?你不会碰巧在 IntelliJ 上吧?
Have you tried typing your command "mvn install" and pressing Command + Enter?您是否尝试过键入命令“mvn install”并按 Command + Enter 键?
I get this all the time and this usually fixes it.我一直得到这个,这通常会解决它。
Install Maven on Mac OS.在 Mac OS 上安装 Maven。 Download the latest version from the Apache Maven site and select the Maven binary tar.gz file, for example, apache-maven-3.8.4-bin.tar.gz.
从Apache Maven 站点下载最新版本并选择 Maven 二进制 tar.gz 文件,例如 apache-maven-3.8.4-bin.tar.gz。
Then we extract the archive to our desired location.然后我们将档案提取到我们想要的位置。
Adding Maven to the Environment Path将 Maven 添加到环境路径
First, let's open the terminal and switch to the directory where the files were extracted to and then log in as superuser or use below commands with sudo.首先,让我们打开终端并切换到文件被提取到的目录,然后以超级用户身份登录或使用以下命令和 sudo。
Second, we need to remove the tar.gz archive:其次,我们需要删除 tar.gz 存档:
rm Downloads/apache-maven*bin.tar.gz
rm 下载/apache-maven*bin.tar.gz
Third, we have to fix the permissions and switch the Maven contents:第三,我们必须修复权限并切换 Maven 内容:
chown -R root:wheel Downloads/apache-maven*
chown -R root:wheel 下载/apache-maven*
mv Downloads/apache-maven* /opt/apache-maven
mv 下载/apache-maven* /opt/apache-maven
Then, let's archive the Admin session and add Maven binaries to the path and append:然后,让我们归档 Admin 会话并将 Maven 二进制文件添加到路径并附加:
exit
出口
nano $HOME/.profile
纳米 $HOME/.profile
export PATH=$PATH:/opt/apache-maven/bin
导出 PATH=$PATH:/opt/apache-maven/bin
Finally, we use Ctrl+x to save and exit from nano.最后,我们使用 Ctrl+x 保存并退出 nano。
To load the new setup, let's run:要加载新设置,让我们运行:
bash Now, we test if Maven is installed successfully using the command below: bash 现在,我们使用以下命令测试 Maven 是否安装成功:
mvn -version
mvn-版本
We are now ready to use Maven on our Mac OS.我们现在已经准备好在我们的 Mac OS 上使用 Maven。
Reference : How to Install Maven on Windows, Linux, and Mac参考:如何在 Windows、Linux 和 Mac 上安装 Maven
如果您使用的是 Mac,则可以使用 Homebrew 安装 maven 及其所有路径使用:
brew install maven
If you want to configure intelliJ terminal with a custom Terminal or if you want fix "command not found", follow these steps:如果要使用自定义终端配置 intelliJ 终端,或者要修复“找不到命令”,请按照下列步骤操作:
// The path you may have differs based on your OS, in example: "installationPath\Terminal Folder\bin\sh.exe --login" // 您的路径可能因您的操作系统而异,例如:“installationPath\Terminal Folder\bin\sh.exe --login”
I used git bash but technically it should work with every terminal.我使用了 git bash 但从技术上讲它应该适用于每个终端。 Do not forget to add --login after the *.exe
不要忘记在 *.exe 之后添加 --login
in my case it was a syntax error:就我而言,这是一个语法错误:
The wrong usage was like this:错误的用法是这样的:
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
export PATH="$PATH:/Applications/Webstorm.app"
I updated:我更新了:
export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"
export PATH="/Applications/Webstorm.app:$PATH"
and now it works现在它可以工作了
First of all Download Maven from here https://maven.apache.org/download.cgi首先从这里下载Maven https://maven.apache.org/download.cgi
and extract it and go and open your zshrc with nano :并提取它和 go 并用nano打开你的zshrc :
nano ~/.zshrc
and paste these lines inside the file:并将这些行粘贴到文件中:
export M2_HOME="/Users/sanaebadi/Downloads/apache-maven-3.8.7"
PATH="${M2_HOME}/bin:${PATH}"
export PATH
** **
you have to make sure that you put your correct USER name instead of my userName (sanaebadi)
你必须确保输入正确的用户名而不是我的用户名 (sanaebadi)
** **
and you have to make sure from the version and directory of your maven that you already downloaded.
并且您必须确保已下载的 maven 的版本和目录。
** **
** **
and relaunch the file after it: source ~./zshrc
然后重新启动文件:
source ~./zshrc
and run this command to make sure you installed the maven on your system:并运行此命令以确保您在系统上安装了 maven:
mvn -version
you must to see some lines start with:你必须看到一些行以:
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /Users/sanaebadi/Downloads/apache-maven-3.8.7 ...
.....
...
Done!完毕!
step 1:步骤1:
vim ~/.zshrc
step 2:(Add at the end of the file)第2步:(在文件末尾添加)
source ~/.bash_profile;
step 3 : (Save changes in Vim)第 3 步:(在 Vim 中保存更改)
:wq!
step 4:(Execution shell)第4步:(执行外壳)
> source ~/.bash_profile
Best solution work for me最适合我的解决方案
Open Finder-> go to folder /Users/ /usr/local/bin打开 Finder-> 转到文件夹 /Users/ /usr/local/bin
open .zshrc with TextEdit使用 TextEdit 打开 .zshrc
.zshrc is hidden file so unhide it by command+shift+. .zshrc 是隐藏文件,所以通过 command+shift+ 取消隐藏。 press
按
delete file content and type删除文件内容和类型
export PATH=~/usr/bin:/bin:/usr/sbin:/sbin:$PATH导出 PATH=~/usr/bin:/bin:/usr/sbin:/sbin:$PATH
and save并保存
now现在
zsh: command not found Gone zsh:找不到命令
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.