Fixing zsh command not found: brew? (installing Homebrew)
Asked Answered
C

7

87

I am trying to install Homebrew onto my M1 Mac. My default shell is zsh and I want to keep it that way. I ran: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and it said the installation was successful however after trying the command brew doctor and brew help both returned the error zsh: command not found: brew

I don't know a whole lot about shells or programming so anything I can try would be helpful.

I then was about to try un/re installing it and ran: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" but a warning came up to migrate to this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

this leads me to believe maybe it is just located in the wrong shell?

Coupling answered 7/1, 2021 at 20:32 Comment(2)
It is saying "brew not found". brew should be in /usr/local/bin/brew. Is it? Is /usr/local/bin in your PATH (in your .zshrc file) ?Lugubrious
Brew does not appear to be in my /usr/local/bin and I don't think I have a .zshrc file.Coupling
D
24

The bash deprecation warning from macOS can safely be ignored, or you can add export BASH_SILENCE_DEPRECATION_WARNING=1 to ~/.bashrc` to permanently silence it.

The initial brew setup script you're using was deprecated, you'll want to use /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)". I've skimmed that script and I think it's actually zsh compatible too, but not 100% sure. This will set it up to be accessible by any shells, as long as you have /usr/local/bin in your PATH. (export PATH="/usr/local/bin:$PATH" in your ~/.zshrc, or path+=/usr/local/bin to use the zsh-specific syntax).

If you run which zsh you should still see some output; if your default shell did get changed some, you can change it back using chsh -s /bin/zsh.

EDIT:

I missed that you said you have an M1 Mac. According to the install script, the brew prefix is /opt/homebrew on ARM-based Macs (apparently this is to work around needing sudo for operations in /usr/local). I don't have a new Mac to test with, but adding path+=/opt/homebrew/bin to a new file at ~/.zshrc should to the trick.

Dicks answered 7/1, 2021 at 23:45 Comment(3)
i can verify that adding path+=/opt/homebrew/bin to ~/.zshrc indeed fixes this on a M1Noland
M1 fix on latest OS (Big Sur 11.21.1) works. After reboot of course.Marginate
if u somehow manage to mess up your shell so that common commands like ls cant even be found, see: #18428874Coats
C
316
cd /opt/homebrew/bin/

PATH=$PATH:/opt/homebrew/bin

cd

touch .zshrc

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

Run the commands in that order in terminal, you'll be editing the path and creating the missing .zshrc file, exporting the path to this new file.

Now you should be able to use:

brew doctor

It should say: "Your system is ready to brew."

Contuse answered 11/4, 2021 at 9:8 Comment(16)
This worked with my M1 MacBook Pro. Thanks dude!Ehman
this worked for my M1 MacBook Air, thanks broKabyle
Is this issue happened only on M1 Apple chip or intel as well? If this is common issue across systems, please mention it.Tingley
thanks worked for my MacBook ProShabby
@Tingley I cannot tell for other systems but I'm on a MacBook Air (M1, 2020), yes.Contuse
cd: no such file or directory: /opt/homebrew/bin/Softwood
This worked with my ZX Spectrum 16K. Thanks pal!Pyroclastic
This worked on macOS Ventura version 13.0.1 Thanks alot!Spanjian
/usr/bin occurs before /opt/homebrew/bin in your PATH. This means that system-provided programs will be used instead of those provided by Homebrew. Consider setting your PATH so that /opt/homebrew/bin occurs before /usr/bin. Here is a one-liner: echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrcWrench
When I ran the first command, "cd /opt/homebrew/bin/: , on MacOS Ventura I got the following error message: cd: no such file or directory: /opt/homebrew/bin/Tryma
worked on M@ MacBook Pro with Ventura 13.2.1 as well. ThanksLenin
This worked with my IMac M1. Thanks bro.Manufacture
@Softwood if you encounter no such file or directory: /opt/homebrew/bin/ then try after below command /bin/bash -c "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/install.sh)"Krakow
Worked on MacBook Air M2Geesey
Worked on MacBook Pro M1Swearingen
sometimes just explaining clearly what to do step by step, rather than being snarky actually helps people to learn why something works! Really great answer.Earshot
V
33

This has helped me:

  • Add Homebrew to your PATH in ~/.zprofile:

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
    
Vituperation answered 5/5, 2021 at 12:22 Comment(1)
This solution does not work for a Mac M3 :(Reilly
D
24

The bash deprecation warning from macOS can safely be ignored, or you can add export BASH_SILENCE_DEPRECATION_WARNING=1 to ~/.bashrc` to permanently silence it.

The initial brew setup script you're using was deprecated, you'll want to use /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)". I've skimmed that script and I think it's actually zsh compatible too, but not 100% sure. This will set it up to be accessible by any shells, as long as you have /usr/local/bin in your PATH. (export PATH="/usr/local/bin:$PATH" in your ~/.zshrc, or path+=/usr/local/bin to use the zsh-specific syntax).

If you run which zsh you should still see some output; if your default shell did get changed some, you can change it back using chsh -s /bin/zsh.

EDIT:

I missed that you said you have an M1 Mac. According to the install script, the brew prefix is /opt/homebrew on ARM-based Macs (apparently this is to work around needing sudo for operations in /usr/local). I don't have a new Mac to test with, but adding path+=/opt/homebrew/bin to a new file at ~/.zshrc should to the trick.

Dicks answered 7/1, 2021 at 23:45 Comment(3)
i can verify that adding path+=/opt/homebrew/bin to ~/.zshrc indeed fixes this on a M1Noland
M1 fix on latest OS (Big Sur 11.21.1) works. After reboot of course.Marginate
if u somehow manage to mess up your shell so that common commands like ls cant even be found, see: #18428874Coats
H
6

i get the seam problem. so i install it again. i copy this command to the terminal.

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

when i get the tips

Next steps:
- Run these three commands in your terminal to add Homebrew to your PATH:
echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/ven/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/ven/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh

than i copy three commands into the termainal one by one

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

typeing 'brew' in the terminal, than it's working.

Hearse answered 31/10, 2022 at 5:39 Comment(1)
NOTE: Commands should be copied from Next steps part of the terminal output (Not here) as it is custom and relfects user name of your mac computer account.Dardan
N
3

I encountered the same issue and solved it with these steps:

  1. From the terminal, command sudo vi ~/.zshrc
  2. Enter insert mode (type I on your keyboard) then paste
    export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
  3. Type :wq! to write and quit vim.
  4. Close the terminal.
  5. Reopen the terminal and type brew to confirm it's working.

If the issue persists:

By default, Homebrew installs some packages in these directories: /usr/local/bin/brew , /usr/local/share/doc/homebrew.

It's worth checking if HomeBrew is inside these. To open finder on a Mac, command + shift + G. If you're unable to locate it, you may need to reinstall it.

I'm using a Macbook, macOS Big Sur - version 11.6.4

Natalee answered 21/4, 2022 at 12:15 Comment(1)
I'm using macOS Monterey version 12.3.1, and this solved the problem for me too. Thank you!Culpa
D
2

In my case (macOS M1) homebrew worked very inconsistently - the not found error appeared every time I ran a brew command in a fresh terminal session. Turns out that the opt/homebrew/... values in .zshrc were getting overwritten by other PATH values at some point. Ordering is crucial here.

So to add to @6754534367 's answer, you want to make sure your PATH reflects homebrew having priority over other PATH values (placed before most other values). See also: https://mcmap.net/q/243441/-adding-homebrew-to-path.

PS: handy to include the sbin PATH too.

In the end my .zshrc file looked as follows (e.g.):

export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/joris.van.der.burgh/Library/Application_Support/JetBrains/Toolbox/scriptseval

After doing so, my homebrew worked consistently and no more doctors were needed.

Duster answered 11/8, 2022 at 14:20 Comment(0)
U
0

In Ubuntu 22.04 the following worked for me

I followed this article

After installing homebrew, I had to do add homebrew to my path like this

(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /path/to/.bashrc

Note: Edit the path to your .baschrc or /zshrc file accordingly. Then do this

eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Ursal answered 9/3, 2024 at 10:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.