➜  ~ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-e:77: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040677
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
The current contents of /usr/local are bin CODEOFCONDUCT.md etc git lib Library LICENSE.txt munki README.md sbin share .git .github .gitignore
➜  ~ brew install maven
zsh: command not found: brew

当前回答

确保先安装brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

其他回答

只需在主目录中添加export PATH=/opt/homebrew/bin:$PATH即可

如果需要重新启动,或者重新打开终端

更新2023

export PATH="/opt/homebrew/bin:$PATH"

我尝试了上面的方法 导出路径= / opt /组装/ bin:美元的道路 但是没有用。

所以我做了我的研究,并意识到上述代码适用于苹果芯片Mac,而不是英特尔芯片Mac。

所以我对代码进行了编辑,因为我的Mac是基于英特尔的,我这样做了,工作完美:

在查找器中,打开/编辑.zshrc文件,如果找不到,则创建一个。 粘贴以下代码:

导出路径= / usr /地方/组装/ bin:美元的道路

会有用的!!

我将演示来自@Spindizzy的答案:

cd ~ | ls -a
touch .zshrc // if file .zshrc doesn't exists we create it
vim .zshrc

将PATH=/opt/homebrew/bin:$PATH粘贴到那里,保存文件并重启终端。

Vim助手:

1. press "i" to interactive mode in vim, paste:
export PATH=/opt/homebrew/bin:$PATH
2. press "esc" type ":wq" and hit enter

我在macOS Big Sur(11.0.1)上遇到了类似的问题。在我的例子中,homebrew保存在/opt/homebrew/,而不是/usr/local/....

所以我补充道

导出路径= / opt /组装/ bin:美元的道路

到我的主目录中的.zshrc文件,并且ZSH shell能够找到brew命令。