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?

  • 3
    Why don't you read your output? It will explain pretty well. – jherran Feb 13 '15 at 17:48
  • As of today, I have the same problem described in the original post. I have a feeling this started right after upgrading OS X to 10.11.2 via the App Store. No matter which parametres are passed to brew, be it 'doctor', 'cleanup' etc., all produce the same output. At least the instruction "brew cleanup" can therefore not be followed. May this have been caused by OS X's SIP? Does anyone have any other ideas? – Axel Kirch Dec 16 '15 at 16:37
  • Welcome to Ask Different. there are two options - you could ask a follow on question showing the results of the rm command or we can vote up / promote this with edits. Also - you could ask - how can I tell if SIP is affecting a specific task. that is answerable and seems a little past the scope of this question so I've be happy to answer that for you elsewhere. The answer is almost surely "no" in homebrew's case. – bmike Dec 16 '15 at 17:26

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.

  • Thank you. For some reason when I did "brew install php54 --with-fpm --with-imap --without-apache --with-debug" it was giving me the first output error from my post. When I tried using "ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/install)"" it gave me the second output error. Restarting my computer and doing what you told me to do really helped. Thank you! – AndrewMRiv Feb 13 '15 at 21:40
  • If using rvm it fails with some "image not found" ruby error; make sure to use sys ruby: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" – tutuDajuju Jun 2 '16 at 12:00
  • 12 hours working. in this bug, just removing homebrew completely I solved. Thanks! – Augusto Xavier Mar 28 '20 at 1:44
  • Ruby installer is deprecated, use /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" instead – kiewic Apr 21 '20 at 15:16

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.

  • 4
    this is the correct answer. – Tamas Kalman Feb 18 '18 at 14:27
  • 1
    Oh my word - possibly having to reinstall everything under brew before cd-ing to a different directory. Yes, this should be the correct answer. – DanSingerman Oct 4 '18 at 14:10
  • I reproduced this behavior by trying to run brew doctor from a directory that has been removed. using cd to switch to a new directory allowed brew doctor to function again. Changing your directory is definitely the correct answer. – sorens Apr 26 '20 at 6:47
  • You are a God among insects. It might literally take me 10 hours to re-install everything in brew I use -.- – syntheticgio Aug 29 '20 at 20:21

If in your homebrew installation you also installed XCode tools on your mac you may just need to close your terminal window and open a new one :)


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .