How to repair and/or reinstall Homebrew safely?

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?


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.


This happened to me because I had two tabs open in my console. In Console A I removed the current working directory of Console B. Then, without thinking about it, I ran brew upgrade in Console B. Of course it threw the above error.

Simple solution: just cd to a different directory in Console B and brew upgrade again.

Me and my infinite wisdom.


I encountered the first error, too. It went away after I exited my shell I used to install Homebrew. Afterwards the brew commands were happy again.