Cannot update HomeBrew: Permission denied

I am trying to fix some brew doctor error but now after manually erased some files that brew doctor suggested I get the following error when trying to do a brew update :

error: cannot open .git/FETCH_HEAD: Permission denied

Error: Failed to update tap: homebrew/versions
Already up-to-date.

Solution 1:

If you are using OSX High Sierra chown operation is not permitted in /usr/local/ in this case use:

sudo chown -R $(whoami) /usr/local/Homebrew/

Solution 2:

I managed to fix this error by fixing the user owner of the /usr/local folder from 504 to Administrator (the user id I am using when I log in to macbook pro terminal).

This was achieved by using this command :

sudo chown -R $USER:admin /usr/local

Solution 3:

sudo chown -R $(whoami):admin /usr/local && sudo chmod -R g+rwx /usr/local