简体   繁体   English

安装 Homebrew 后,我得到 `zsh: command not found: brew`

[英]After installing Homebrew I get `zsh: command not found: brew`

➜  ~ /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

I had a similar issue on macOS Big Sur (11.0.1).我在 macOS Big Sur (11.0.1) 上遇到了类似的问题。 In my case homebrew was saved in /opt/homebrew/ , and not in /usr/local/... .在我的情况下,自制软件保存在/opt/homebrew/ ,而不是保存在/usr/local/...

So I added所以我加了

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

to .zshrc file in my home directory, and the ZSH shell was able to find the brew command..zshrc在我的主目录文件,zsh的外壳能够找到冲泡命令。

for this error zsh: command not found: brew对于此错误zsh: command not found: brew

  1. Make sure you've installed Brew, with this (wait until its done installing)确保您已经安装了 Brew(等待安装完成)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
  1. Then follow NEXT STEPS shown on command line, it should show something like this然后按照命令行上显示的NEXT STEPS进行操作,它应该显示如下内容
==> Next steps:
- Add Homebrew to your PATH in /Users/$USER/.zprofile:
    echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
    eval $(/opt/homebrew/bin/brew shellenv)
  1. Copy and paste the first line on the same terminal window, then hit enter将第一行复制并粘贴到同一终端窗口中,然后按 Enter
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/$USER/.zprofile
  1. Then Copy and paste the last line on the same terminal window, then hit enter然后将最后一行复制并粘贴到同一终端窗口中,然后按 Enter
eval $(/opt/homebrew/bin/brew shellenv)

Finally you should be able to use brew help and if that works, it means that brew was installed properly and running from ZSH .最后,您应该能够使用brew help ,如果有效,则意味着 brew 已正确安装并从ZSH运行。

Update 2023 2023 年更新

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

Homebrew has been installed on you computer. Homebrew 已安装在您的计算机上。 You need to modify your PATH like this:您需要像这样修改 PATH:

export PATH=/usr/local/bin:$PATH

or execute brew from its origin:或者从它的原点执行brew

/usr/local/bin/brew install maven

Here are the steps I did...这是我做的步骤...

1.Install homebrew 1.安装自制软件

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2.Run brew help and see if it's working... If it showing an error "zsh: command not found: brew" follow along. 2.运行brew help并查看它是否正常工作...如果它显示错误“zsh: command not found: brew”,请继续。

  1. Change the path to:将路径更改为:
echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/"YOUR USER NAME"/.zprofile

Remember to change the "USER NAME" with yours, Then type in:请记住将“用户名”更改为您的,然后输入:

eval $(/opt/homebrew/bin/brew shellenv)

Once successfully running these command type "brew help" to see if everything went ok.成功运行这些命令后,键入“brew help”以查看是否一切正常。

确保先安装 brew

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

I got the same issue after installing Homebrew in my MacBook (macOS Big Sur V 11.0.1).在我的 MacBook(macOS Big Sur V 11.0.1)中安装 Homebrew 后,我遇到了同样的问题。

After installation, in the console it says what should be done,安装后,在控制台中它会说应该做什么,

==> Next steps:
- Add Homebrew to your PATH in /Users/samme/.zprofile:
    echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/samme/.zprofile
    eval $(/opt/homebrew/bin/brew shellenv)
- Run `brew help` to get started

Executing above two commands in order, will add the brew command into the PATH.按顺序执行以上两个命令,会将 brew 命令添加到 PATH 中。

In fish shell on Apple M1, I had to add /opt/homebrew/bin to the fish_user_paths global env.fish上苹果M1外壳,我不得不添加/opt/homebrew/binfish_user_paths全球ENV。 I had to do this manually because set -U fish_user_paths /opt/homebrew/bin $fish_user_paths got我必须手动执行此操作,因为set -U fish_user_paths /opt/homebrew/bin $fish_user_paths得到了

set: Universal variable 'fish_user_paths' is shadowed by the global variable of the same name.设置:通用变量“fish_user_paths”被同名的全局变量遮蔽。

Just add export PATH=/opt/homebrew/bin:$PATH in your home directory只需在您的主目录中添加export PATH=/opt/homebrew/bin:$PATH

Restart if needed or just reopen your terminal如果需要,重新启动或重新打开您的终端

When installing, brew has this -NEXT STEPS console log when is needed to include its path to bash.安装时,brew 在需要包含其到 bash 的路径时具有此 -NEXT STEPS 控制台日志。

run the followed steps:运行以下步骤:

`echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/YOUR_USER/.zprofile`

`eval "$(/opt/homebrew/bin/brew shellenv)"`

For the latest version as of 6-oct-2022...对于截至 2022 年 10 月 6 日的最新版本...

==> Next steps: ==> 后续步骤:

  • Run these three commands in your terminal to add Homebrew to your PATH:在您的终端中运行这三个命令以将 Homebrew 添加到您的 PATH:

    echo '# Set PATH, MANPATH, etc., for Homebrew.' echo '# 为 Homebrew 设置 PATH、MANPATH 等。 >> /Users/tusharkhatri/.zprofile >> /用户/tusharkhatri/.zprofile

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/tusharkhatri/.zprofile echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/tusharkhatri/.zprofile

    eval "$(/opt/homebrew/bin/brew shellenv)"评估“$(/opt/homebrew/bin/brew shellenv)”

  • Run brew help to get started运行 brew help 开始

  • Further documentation: https://docs.brew.sh更多文档: https://docs.brew.sh

This morning i too faced the same issue.今天早上我也面临同样的问题。 The problem is path for homebrew is not set correctly.问题是自制程序的路径设置不正确。

Follow below steps按照以下步骤操作

1.install homebrew correctly. 1.正确安装自制软件。 In the terminal type below cmd.在cmd下面的终端类型中。

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

  1. set the path in your .zshrc file in terminal type在终端类型的 .zshrc 文件中设置路径

    open ~/.zshrc打开 ~/.zshrc

    In .zshrc file add the path like below在 .zshrc 文件中添加如下路径

    export PATH="/usr/local/bin:$PATH"导出路径="/usr/local/bin:$PATH"

  2. In terminal type source ~/.zshrc在终端输入 source ~/.zshrc

    and your done.和你的完成。

I tried the above method export PATH=/opt/homebrew/bin:$PATH But it didnt work.我尝试了上面的方法 export PATH=/opt/homebrew/bin:$PATH 但它没有用。

So i did my research and realized that the above code works for Apple chip Mac and not for intel chip Mac.所以我做了我的研究并意识到上面的代码适用于苹果芯片 Mac 而不是英特尔芯片 Mac。

So i made an edit to the code since my Mac is intel based and i did this which worked perfectly:所以我对代码进行了编辑,因为我的 Mac 是基于英特尔的,而且我这样做效果很好:

  1. In your finder, open/edit the.zshrc file or create one if you cannot find it.在您的查找器中,打开/编辑 .zshrc 文件,如果您找不到它,则创建一个。

  2. paste this code:粘贴此代码:

export PATH=/usr/local/homebrew/bin:$PATH导出 PATH=/usr/local/homebrew/bin:$PATH

It will work!!!它会工作!

If you're on WSL2 make sure to follow the final linux installation instructions for linuxbrew.如果您使用的是 WSL2,请确保遵循 linuxbrew 的最终 linux安装说明

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Go to the official Homebrew site .转到Homebrew官方网站

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Next steps:下一步:

test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile

Try: brew install hello尝试: brew install hello

Basically your homebrew is saved in /opt/homebrew/, and not in /usr/local/.... path基本上你的自制软件保存在 /opt/homebrew/ 中,而不是 /usr/local/.... 路径

Open .bash_profile in your home directory and add :在您的主目录中打开 .bash_profile 并添加:

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

and restart the terminal.并重新启动终端。 You will have it up and running.您将启动并运行它。

check the below link, there you can set up Homebrew (brew) command with permanent set up path in .zshrc file检查以下链接,您可以在那里设置 Homebrew (brew) 命令和 .zshrc 文件中的永久设置路径

How to install homebrew on M1 mac 如何在 M1 mac 上安装自制软件

I had the same issue with Ubuntu and Arch Linux.我在 Ubuntu 和 Arch Linux 上遇到了同样的问题。 I solved this problem by adding the path of the bin folder of brew to the .zshrc file.我通过将brew的bin文件夹的路径添加到.zshrc文件中解决了这个问题。

The path to my brew installation bin directory is /home/linuxbrew/.linuxbrew/bin我的brew安装bin目录的路径是/home/linuxbrew/.linuxbrew/bin

Add following line to the ~/.zshrc file ~/.zshrc下行添加到~/.zshrc文件中
export PATH=/home/linuxbrew/.linuxbrew/bin:$PATH

After this do open a new terminal and the brew command will not be available.在此之后打开一个新终端并且 brew 命令将不可用。

I just did echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc as I'm using oh-my-zsh .我只是echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc as I'm using oh-my-zsh After doing this should be able to use brew.这样做之后应该就可以使用brew了。

Since you're using zsh, you need to add the PATH to your .zshrc file:由于您使用的是 zsh,您需要将 PATH 添加到您的 .zshrc 文件中:

vim ~/.zshrc

Add:添加:

export BREW_HOME="/home/linuxbrew/.linuxbrew/bin"
export PATH="$PATH:$BREW_HOME"

To your .zshrc file, add the path to your homebrew/bin , wherever that might be.在您的.zshrc文件中,添加homebrew/bin的路径,无论它在哪里。 In my case, homebrew was installed in my home directory.就我而言, homebrew安装在我的主目录中。 Add:添加:

export PATH="/<path-to-homebrew-directory>/bin:$PATH"

Restart your terminal for it to pick up the changes to your .zshrc重新启动您的终端以获取对.zshrc的更改

I will just demonstrate the answer from @Spindizzy terminally speaking:我将只展示@Spindizzy 最终的答案:

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

Paste PATH=/opt/homebrew/bin:$PATH there, save file and restart terminal .在那里粘贴PATH=/opt/homebrew/bin:$PATH ,保存文件并重新启动终端

Vim helper: Vim 助手:

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

may be you have followed this step from homebrew homepage.可能是您从 homebrew 主页遵循了此步骤。

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

so may your system not able to allocate path so follow below steps.因此您的系统可能无法分配路径,因此请按照以下步骤操作。

sudo nano /etc/paths

paste粘贴

/opt/homebrew/bin:$PATH

save and close保存并关闭

edit .zshrc编辑 .zshrc

nano .zshrc

add添加

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

就我而言,我将以下行添加到 ~/.zshrc

eval "$(/opt/homebrew/bin/brew shellenv)"

Solution for Ubuntu 20.04解决方案 Ubuntu 20.04

  1. After installing brew with:安装 brew 后:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  2. and ran what it says after (this did nothing for me just added lines to .zprofile every time i ran it):然后运行它之后的内容(这对我没有任何作用,只是在每次运行时向.zprofile添加行):

    echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/blcuser/.zprofile

    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"

  3. BEFORE closing that terminal copy the output of:在关闭该终端之前copy output 的:

    echo $PATH

  4. Should be similar to this:应该类似于这样:

/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

What we need is the path to brew which is this part of the previews path (for you might be a different path)我们需要的是path to brew这是预览路径的这一部分(因为你可能是不同的路径)

/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin

  1. Open NEW terminal and try to build the whole first path with:打开NEW终端并尝试构建整个第一条路径:

Should be like: <brew_path>:$PATH应该是这样的: <brew_path>:$PATH

For me was this: echo /home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH对我来说是这样的: echo /home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH

Should output the first whole path we output on 4.应该 output 第一个完整路径我们 output 上4.

  1. Open .zshrc file (mine is on home hidden file)打开.zshrc文件(我的是home隐藏文件)

  2. At the beginning of the .zshrc file add what we build on 5. :.zshrc文件的开头添加我们在5.上构建的内容:

    export PATH=/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH

  3. Save and restart terminals保存并重启终端

  4. Check that is working with:检查是否正在使用:

    brew doctor

You should be set and brew should be started always with new terminals by default.默认情况下,您应该设置并且 brew 应该始终使用新终端启动。

Maybe it's not so obvious but in addition to the above steps, check your .zshprofile is not corrupted with any extraneous quotation marks.也许它不是那么明显,但除了上述步骤之外,请检查您的.zshprofile是否被任何多余的引号损坏。 You should also close all terminal instances.您还应该关闭所有终端实例。

16.11.2022 - Update 16.11.2022 - 更新
During brew installation I got multiple lines informing me about where brew will be installed.在 brew 安装过程中,我收到多行通知我将安装 brew 的位置。 For me terminal said:对我来说终端说:

This script will install:
...
/usr/local/Homebrew

So path I needed was the last one.所以我需要的路径是最后一条。 Steps to fix the issue:解决问题的步骤:

  1. Edit .zshrc file.编辑.zshrc文件。 Type:类型:

    nano ~/.zshrc

  2. Add line in the editor:在编辑器中添加行:

    export PATH=/usr/local/homebrew/bin:$PATH

  3. Hit Control+X to Exit the editor, Y to accept the changes and return to accept where file is going to be saved.Control+X退出编辑器,按Y接受更改并return以接受要保存文件的位置。

After all you need to refresh the terminal you use.毕竟你需要刷新你使用的终端。 You can either close the process of it and open or type:您可以关闭它的进程并打开或键入:

source ~/.zshrc

That's it.而已。 Hope it helped.希望它有所帮助。

It help me.它帮助我。 Just run follow command:只需运行以下命令:

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/gureenkov56/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/gureenkov56/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

might be late, but surely helpful.可能会迟到,但肯定会有所帮助。 you have to install brew on first thing.你必须首先安装 brew。 just run the below command to do that:只需运行以下命令即可:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Run the following setup then you will be ready to use brew运行以下设置,然后您就可以使用 brew

Run unintsall script:-运行 unintsall 脚本:-

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

Set Git Compression:- git config --global core.compression 0设置 Git 压缩:- git config --global core.compression 0

Set Git buffer size:- git config --global http.postBuffer 1048576000设置 Git 缓冲区大小:- git config --global http.postBuffer 1048576000

Run installation script:- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"运行安装脚本:- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

You should add both /opt/homebrew/bin and /opt/homebrew/sbin to $PATH env.您应该将/opt/homebrew/bin/opt/homebrew/sbin添加到$PATH环境中。

export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH导出 PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH

for quick, run command快速运行命令

echo export PATH=$PATH:/opt/homebrew/bin:/opt/homebrew/sbin >> ~/.zshrc

then run brew doctor to checking然后运行brew doctor检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM