not able to install anything because of brew no such file or directory error

Try uninstalling Homebrew and then re-installing solved issue for me.

Uninstall Homebrew:

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

Re-install Homebrew:

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

Performed in MacOS Mojave (10.14.4)


I experienced a similar error with a different package - brew install llvm.

Uninstalling homebrew and reinstalling led to more catastrophic issues that lasted for hours before I had to reach for my backup drive and restore everything. What eventually worked was just creating the missing directory and everything worked. So in this case:

sudo mkdir /usr/local/Cellar/dir_chdir

should solve the issue without too much hustle.