`brew: command not found` after first install

What you were trying to do (and why)

Install Homebrew.
Please note that I found and read a similar issue (https://github.com/Homebrew/brew/issues/4243). I used the suggested solution of changing $PATH, and it did not work.

What happened (include command output)

  1. Logged into Admin user.
  2. In the /usr/local directory, followed this direction (https://docs.brew.sh/Installation#untar-anywhere) and ran this command: mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  3. Got a bunch of permission errors (could not scroll back far enough in the terminal to copy them).
  4. Tried again with sudo: sudo mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  5. Typed in brew help, and got -bash: brew: command not found.
  6. Tried this instead to do the install again:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  7. Typed in brew help, and got -bash: brew: command not found.
  8. Checked xcode-select was installed
  9. Tried editing the path: export PATH="/usr/local/bin:$PATH"
  10. Bash still didn’t recognize the brew command.
  11. Tried changing owner a couple of different ways and ran into permission errors:
    • sudo chown -R $USER /usr/local/lib /usr/local/include /usr/local/bin /usr/local/Cellar
    • sudo chown -R $USER $(brew --prefix)/*
  12. Ran the install command again: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  13. Ran sudo chown -R $USER:admin /usr/local. Output: chown: /usr/local: Operation not permitted
  14. brew was still not recognized as a command.
Command output
# When running `brew help`:
 `-bash: brew: command not found`
# When re-running the install:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made writable by user only:
/usr/local/share/zsh
/usr/local/share/zsh/site-functions

Press RETURN to continue or any other key to abort
Password:
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> Downloading and installing Homebrew…
/usr/local/homebrew/.git: Permission denied
Failed during: git init -q
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations

fatal: not in a git directory
Failed during: git config --replace-all homebrew.analyticsmessage true
==> Next steps:

What you expected to happen

After I saw Installation successful! in the command output, I expected
brew help to print documentation. Then, after I had tried the path change and owner change, I expected bash to recognize brew.

Step-by-step reproduction instructions (by running brew commands)

Please note that bash would not even recognize brew as a command.
As listed in the answer to a previous question, this is what I did, step-by-step:

  1. Logged into Admin user.
  2. In the /usr/local directory, followed this direction (https://docs.brew.sh/Installation#untar-anywhere) and ran this command: mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  3. Got a bunch of permission errors (could not scroll back far enough in terminal to copy them).
  4. Tried again with sudo: sudo mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  5. Typed in brew help, and got -bash: brew: command not found.
  6. Tried this instead to do the install again:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  7. Typed in brew help, and got -bash: brew: command not found.
  8. Checked xcode-select was installed
  9. Tried editing the path: export PATH="/usr/local/bin:$PATH"
  10. Bash still didn’t recognize the brew command.
  11. Tried changing owner a couple of different ways:
    • sudo chown -R $USER /usr/local/lib /usr/local/include /usr/local/bin /usr/local/Cellar
    • sudo chown -R $USER $(brew --prefix)/*
  12. Ran the install command again: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  13. Ran sudo chown -R $USER:admin /usr/local. Output: chown: /usr/local: Operation not permitted
  14. brew was still not recognized as a command.

Output of brew config and brew doctor commands

`-bash: brew: command not found`

Run sudo chown -R $USER:admin /usr/local/*

And then try the installer again. Chown is blocked on /usr/local by SIP.

2 Likes

Thanks; before I got this message I tried running the install command again: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" and everything worked.

1 Like

Hello, I have some trouble about my Brew because my terminal it does not recognize the brew and put the code line that you indicated sudo chown -R USER: admin / usr / local / *. But the word (base) appeared on the first line of the terminal at the start (base) Users-MacBook-Pro: ~ user . How can I go back to how I was without this word (base)? since I don’t know very well what the expression chown -R $ USER means: admin / usr / local / *. I would appreciate help on this. Cheers

These are shell settings and usually represent the local directory or git branch. This is just information and doesn’t actually impact the functions in your terminal.

sudo chown -R $USER:admin /usr/local/*

  • sudo means “run the next code as another user” with the default being the administrator user. That’s what we’re using it for here.

  • chown is the command to change the owner of a directory or file.

  • -R means this directory and all directories contained in it are getting a new owner.

  • $USER:admin is the new owner and group of the file/directory. With $USER being replaced by the current username when you run this command.

  • /usr/local/* this means all files and directories in /usr/local. This is the location where homebrew installs and is expected to be owned by the user for homebrew to work.

Captura de pantalla 2020-04-28 a las 9.05.27 PM For some reason impact and appears this word (base) in the beginning, maybe for the -R of a new owner?. How i can come back as a default of fabric?. Greetings!

That’s not a homebrew related question at all, I have no idea what you did to do that, nor is it related to homebrew.

That´s ok I understand I just type the line code that you put: sudo chown -R $USER:admin /usr/local/* and this happens. Best

Resolved my issue :100: