Note: I\'m not so good at using shell.
I was trying to install Valgrind using brew on Yosemite.
Valgrind
brew
brew install --HEAD valgrind<
I had same problem and i resolved with next solution: Run brew doctor from Terminal to check all your errors
then run next command:
sudo chown -R $USER:admin /usr/local/bin /usr/local/etc /usr/local/sbin /usr/local/share
after run:
brew link