53

I ran the following command on terminal (Mac El Capitan)

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

and got the following error message:

Failed during: git fetch origin master:refs/remotes/origin/master -n --depth=1

Additionally tried:

sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local

then the two commands above.

Any idea how to install Homebrew?

brew is not recognized and ruby version 2.0.0, git version 2.7.4

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
anm
  • 1,865
  • 3
  • 19
  • 28
  • Deleting folder `/usr/local/Homebrew` and retrying (once) was good enough on macOS Big Sur 11.2. – Jagdeep Singh Feb 11 '21 at 06:55
  • 1
    I had the same problem after an aborted install I used `find / -name "brew" 2> /dev/null` to find every brew data and rm -rf'd it, in particular `sudo rm -rf /opt/homebrew`. – Yann Pellegrini Mar 04 '22 at 14:13

19 Answers19

93

After a few hours of research and brute force I learned the issue was due to git not being configured properly. Some articles suggested downgrading your git or reinstalling all together. However, I resolved the issue just by adding the following

git config --global user.email yourgitemail@example.com

Then remove the cellar and homebrew directories from /usr/local and re-try the installation.

Nicu Surdu
  • 8,172
  • 9
  • 68
  • 108
anm
  • 1,865
  • 3
  • 19
  • 28
  • 7
    Just deleting the `cellar` and `homebrew` directories did the trick for me. (for me above error occurred because my machine shutdown during the installation) Thank you very much for the answer @anm . – Tharusha Oct 25 '18 at 06:31
  • 12
    For me only deleting the `Homebrew` folder was more than enough :) – Manuel van Rijn Dec 21 '18 at 09:22
  • 50
    For Apple silicon (arm64) i.e. M1 chips, @anm answer worked for me but only after doing `sudo rm -rf /opt/homebrew` and then retry `/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` I came to this by checking the contents of the install script https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh – Cato Apr 10 '21 at 16:57
  • After following the suggested steps: `zsh: command not found: brew` – zaggi Aug 17 '21 at 12:04
  • I just removed Cellar and Homebrew folders from /usr/local then reinstall homebrew.. works for me 100% – GinealSoftwareDev Dec 11 '21 at 08:39
  • Maybe this changed recently, but note that in the latest version of brew, the folders are `Cellar` and `Homebrew` (with capital letters) – Nicu Surdu May 03 '22 at 08:46
  • @Cato 's answer is worked for me. thanks. After following his steps, I did this: echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/USERNAME/.zprofile echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/USERNAME/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)" – Chamara Indrajith Nov 15 '22 at 15:51
35
  1. create a file named run.sh
  2. add this:
rm -rf /usr/local/bin/brew
rm -rf /usr/local/share/doc/homebrew
rm -rf /usr/local/share/man/man1/brew.1
rm -rf /usr/local/share/zsh/site-functions/_brew
rm -rf /usr/local/etc/bash_completion.d/brew
rm -rf /usr/local/Homebrew
  1. run the file using sh run.sh

Or, just run all these commands manually one by one.

Ash Singh
  • 3,921
  • 2
  • 25
  • 30
  • 12
    good answer, and for mac m1 Big Sur, add another line `rm -rf /opt/homebrew` – Sinux Jan 03 '21 at 07:58
  • 1
    This work for me. If you also facing issues on [!] Error installing XXX while executing pod install. Try this answer. Thanks for saving my day – Ryan Jan 04 '21 at 15:27
  • 1
    This worked for me executing @ashdaily commands, addindo `sudo` to last command and then the @Sinux command too. I'll put down the complet command set for being eaier to read. – Ricardo Barroso Apr 18 '21 at 10:33
  • 1
    This did it for my M1 mac – fabio.sang Jul 27 '21 at 17:13
  • this didn't work for me. I have an M1 mac. I was using version 11, I have updated the big sur and started to use the 12.1 version. And the problem is solved now, I installed brew without any issue. – emily.mi Jan 06 '22 at 22:19
16

@ashdaily commands worked for me, addindg sudo on last command and then executing also the @Sinux command too:

rm -rf /usr/local/bin/brew
rm -rf /usr/local/share/doc/homebrew
rm -rf /usr/local/share/man/man1/brew.1
rm -rf /usr/local/share/zsh/site-functions/_brew
rm -rf /usr/local/etc/bash_completion.d/brew
sudo rm -rf /usr/local/Homebrew
rm -rf /opt/homebrew
Ricardo Barroso
  • 634
  • 9
  • 11
15

Fastest and easiest way is to uninstall Homebrew by following command -

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

and after this, fresh install of Homebrew by following command -

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Robert Baker
  • 25,593
  • 1
  • 20
  • 21
Himanshu Gupta
  • 151
  • 1
  • 2
7

Steps to fix it on Big Sur (2021):

  1. git config --global user.email yourgitemail@example.com
  2. Remove the cellar and homebrew directories from /usr/local
  3. Re-try the installation

Works for me on Big Sur.

cavalcantelucas
  • 1,362
  • 3
  • 12
  • 34
Lucas
  • 71
  • 1
  • 1
5

To fix the issue on Monterey:

1. sudo rm -rf /opt/homebrew/
2. git config --global user.email username@example.com

After executing the steps, try back the installation

burak isik
  • 395
  • 5
  • 6
4

You can solve this issue for Apple silicon (arm64) M1 chips by running following commands:

  1. sudo rm -rf /opt/homebrew
    
  2. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
Muhammad Haidar
  • 1,541
  • 16
  • 17
3
  • New home-brew will installed in /opt/homebrew/ folder.
  • If some errors happened at installation you need to reinstall all.
  • Try to clean all trashes with sudo rm -rf /opt/homebrew/ command
  • Tested and It's worked (12 September 2021)

Also, may you need to configure git config --global user.email yourgitemail@example.com

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
yEmreAk.com
  • 3,278
  • 2
  • 18
  • 37
2

just do this little code

rm -fr $(brew --repo homebrew/core) # because you can't brew untap homebrew/core
brew tap homebrew/core
Victor Anuebunwa
  • 2,553
  • 2
  • 24
  • 34
Fillz Adebayo
  • 420
  • 3
  • 6
2

Make sure you disable any ISP related 'child safe' settings.

I've been pulling my hair out with this for the last few hours - turned out that it was my ISPs 'child safe' settings (recently switched to Virgin Media) Hope this helps someone who's tried all the above and still having problems.

Simon
  • 21
  • 1
2

Deleting /opt/homebrew directory worked for me.

I am using Macbook air M1

  • This is a duplicate because a number of existing answers detail removing `/opt/homebrew`. When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers. Remember to review all existing answers first. – tjheslin1 Apr 13 '22 at 21:20
  • 1
    This works but need to delete all the homebrew directories on your machine – ekibet Jul 30 '22 at 09:47
1

On linux the default installation happens at /home/linuxbrew

Just delete the /home/linuxbrew: sudo rm -rf /home/linuxbrew

Shahzaib
  • 313
  • 2
  • 8
1
sudo rm -rf /usr/local/HomeBrew
sudo rm -rf /opt/homebrew/

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

If it still doesn't work, try setting you email for git client

git config --global user.email yourgitemail@example.com
Junaid
  • 4,682
  • 1
  • 34
  • 40
1

If you're using M1 mac, probably homebrew packages were installed in /opt/.

Try deleting packages like this:

sudo rm -rf /opt/homebrew/bin/brew \
rm -rf /opt/homebrew/share/doc/homebrew \          
rm -rf /opt/homebrew/share/man/man1/brew.1 \
rm -rf /opt/homebrew/share/zsh/site-functions/_brew \
rm -rf /opt/homebrew/etc/bash_completion.d/brew \
rm -rf /opt/homebrew

worked for me. :)

isaadabbasi
  • 101
  • 5
0

On ARM (Mac with Apple Silicon) you should delete the hombrew under /opt

sudo rm -rf /opt/homebrew/
0

First uninstall homebrew with the following code

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

Then uninstall the packages that were installed when trying to install Homebrew by running the following code one by one

sudo rm -rf /opt/homebrew/bin/brew \
sudo rm -rf /opt/homebrew/share/doc/homebrew \          
sudo rm -rf /opt/homebrew/share/man/man1/brew.1 \
sudo rm -rf /opt/homebrew/share/zsh/site-functions/_brew \
sudo rm -rf /opt/homebrew/etc/bash_completion.d/brew \
sudo rm -rf /opt/homebrew

Finally, go ahead to install homebrew again

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

Uninstall Homebrew and install it again and is gonna work!!

  • 1
    Since this is the same solution as all the other existing answers recommend, just without code or any other better explanation, I assume that you post this only for saying thanks. In that case please delete this. Otherwise please [edit] to make more obvious what new insight your post contributes to the problem solving. Please consider taking the [tour], it will help you undestand the concepts of StackOverflow. – Yunnosch Dec 30 '22 at 08:24
0

I found this very useful

If one sees, 'git [...] -- [...]' , wait patiently. It's still trying to install

If one sees, Failed during: /home/linuxbrew/.linuxbrew/bin/brew update --force --quiet

do /home/linuxbrew/.linuxbrew/bin/brew update-reset and reinstall

https://github.com/orgs/Homebrew/discussions/666

0

In addition to having to delete the directories, sometimes yo need to do the following:

 git config --global --unset http.proxy
 git config --global --unset https.proxy