cocoaPods pod install Permission denied

godzilla picture godzilla · Apr 17, 2013 · Viewed 37.9k times · Source

This is the short version:

When I run

pod install 

in an Xcode project I get

[!] Pod::Executable pull error: cannot open .git/FETCH_HEAD: Permission denied

If I run

sudo pod install

I get no error, but my files installed are owned by root and can't compile and I have to chown those files to a normal user to use the Xcode compiler.

I am running Lion OSX.

I installed cocoaPods using

sudo gem install cocoaPods

I had to use sudo because without it I got

ERROR: While executing gem ... (Gem::FilePermissionError)

You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.

so now I have a root installed version of cocoaPods that downloads root owned Xcode libraries.

Is sudo installation of cocoaPods the wrong way or normal way?

If normal, is there a way to fix the pod install problem?

Answer

jianpx picture jianpx · Jul 9, 2013

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.