I’m at the end of my rope here and hope you guys & gals can help out.

I use the package bash-completion via brew, and, after this morning, I get this message when I open a new iTerm2 tab:

-bash: brew: command not found

Afterwards, I can execute brew without errors.

I have this if block in my .bashrc file, which gets sourced by .bash_profile:

if [ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]
  source "/opt/homebrew/etc/profile.d/bash_completion.sh"

All of a sudden this isn’t enough, which is confusing because if always have been working until this morning. I installed the latest version of PHP this morning, run brew doctor and added /opt/homebrew/sbin to my $PATH, removed PHP and orphaned packages but nothing seems to change the message I get.

If I remove the if statement above the message disappears.

I have no clue how and why and was wondering if someone can help me out.

echo $PATH:


type brew:

brew is /opt/homebrew/bin/brew

ls -l /opt/homebrew/bin/brew?:

-rwxr-x---@ 1 john  admin   4.9K May 22 07:03 /opt/homebrew/bin/brew
  • Paste of my .bashrc: link
  • Paste of my .bash_profile: link
  • If type works, shouldn‘t brew as well?
    – nohillside
    Commented May 22, 2023 at 8:15
  • Can you post the output of ls -l /opt/homebrew/bin/brew?
    – jaume
    Commented May 22, 2023 at 10:03
  • 1
    @jaume: Output: -rwxr-x---@ 1 john admin 4.9K May 22 07:03 /opt/homebrew/bin/brew
    – user496554
    Commented May 22, 2023 at 10:35
  • 4
    if it only occurs once within a new tab, there is something in your startup files which calls brew before the path is set correctly.
    – nohillside
    Commented May 22, 2023 at 10:46
  • 2
    .bashrc is sourced for every non-login, interactive shell first. This the tab(s) you open after the first one. .bash_profile is sourced on the login interactive shell (first one). Where in .bash_profile do you source .bashrc? Can you post your .bash_profile and .bashrc to pastebin or similar?
    – Allan
    Commented May 22, 2023 at 13:07

1 Answer 1


The issue is that when you try to run the bash_completion.sh file brew is not on your $PATH.

The fix is to move the line where you set $PATH to be above the test for bash_completion.sh file ie your .bashrc has these commands as

# Prepend brew and $HOME/bin to $PATH
export PATH="/opt/homebrew/bin:""/opt/homebrew/sbin:""$HOME/.bin"":$PATH"

# Bash completion
if [ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]
  source "/opt/homebrew/etc/profile.d/bash_completion.sh"
  • This solved my issues instantly. Thank you all for helping me.
    – user496554
    Commented May 23, 2023 at 7:43
  • 1
    /opt/homebrew/etc/profile.d/bash_completion.sh is just a wrapper for /opt/homebrew/Cellar/bash-completion/1.3_3/etc/bash_completion. Interestingly enough, brew seems to get called from neither. But hey, if it works, great :-)
    – nohillside
    Commented May 23, 2023 at 8:40
  • @nohillside: Indeed, I’m glad that pesky message disappeared but still scratch my head as in how.
    – user496554
    Commented May 23, 2023 at 9:33
  • I just tried with a shell without homebrew in the path. Sourcing /opt/homebrew/etc/profile.d/bash_completion.sh worked without a problem. Makes me wonder what kind of side-effect the edit described in the answer had.
    – nohillside
    Commented May 23, 2023 at 11:59
  • @qwewrerhtjykuhlj Do you have a ~/.bash_completion?
    – nohillside
    Commented May 23, 2023 at 12:02

You must log in to answer this question.