cocoaPods pod install Permission denied

I solved this problem by running the following command:

sudo chown -R $USER ~/Library/Caches/CocoaPods

and

sudo chown -R $USER ~/.cocoapods

Please replace username and groupname with your Mac login username/groupname.


I only used (where username is your Mac login username)

sudo chown -R username ~/Library/Caches/CocoaPods

and

sudo chown -R username ~/.cocoapods

when I tried with the groupname parameter I got

chown: username.groupname: illegal user name

Of course I used my own username and groupname :)


Removing the directories worked for me:

sudo rm -R  ~/Library/Caches/CocoaPods
sudo rm -R  ~/.cocoapods/repos

If some other problems still exist.

Remove the Pods directory and the podFile.lock file.

Cocoapods just adds the directories again.