How to fix homebrew error: "invalid active developer path" after upgrade to OS X El Capitan?
Run the following commands to fix the above error

sudo xcode-select --install
sudo xcode-select -switch /


I found the answer on https://github.com/Homebrew/homebrew/issues/23500

I also had to do this:

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


Because of some permission issues. However, do this only if you have to.