MacOS – How to repair and/or reinstall Homebrew safely

command linehomebrewmacosterminal

I am trying to repair Homebrew.

I recently tried to reinstall it but when I typed "brew doctor"

My output was:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
The current working directory doesn't exist, cannot proceed.

I have tried to re-install it by typing this into the command line again:

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

But my output is:

It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

How can I fix my Homebrew install?

Best Answer

Why don't you do what it says?

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The first line is going to delete homebrew completely and then you should be able to reinstall it.

NOTE: If you do this you'll have to reinstall all the things you installed via homebrew.