I have been using Mac terminal to get a MAMP setup done lately and I kept running back in to and error I spent a lot of time trying to fix a while ago…sigh. This comes up when you try to install or update with brew.
Irshads-MBP:~ Ishy$ brew upgrade Error: Cannot write to /usr/local/Cellar
Fix it this way:
sudo chown -R $USER /usr/local
Note: You can replace $USER to root as homebrew is better set with root.