57

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?

10 Answers 10

107

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.

9
  • Note, you need to have the username you are transferring ownership to between the -R and ~filename
    – lehn0058
    Jul 10, 2013 at 16:26
  • to @lehn0058, I am sorry to missing the username parameter in a hurry.
    – jianpx
    Jul 10, 2013 at 16:32
  • 3
    As a side note, the incident occurred because i ran 'sudo pod setup' instead of 'pod setup'. Jan 6, 2014 at 10:00
  • 12
    You should be able to replace username.groupname with $USER and it should work with a straight copy paste for anyone. Worked a charm anyway thanks.
    – Adam Waite
    Jan 20, 2014 at 10:54
  • 1
    To know your username just type: whoami
    – skywinder
    Apr 28, 2014 at 12:19
22

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 :)

1
  • 2
    I have resolved the issue by removing the content in the ~/Library/Caches/CocoaPods and then go to the project directory and pod install May 8, 2014 at 13:05
11

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.

2
  • 2
    ~/Library/Caches/CocoaPods/GitHub does not exist.
    – Raptor
    Apr 2, 2014 at 3:21
  • which version of CocoaPods do you have? Jul 1, 2014 at 9:46
5

The issue is with Mac OS X's default installation of Ruby. The Ruby/Gems installation is owned by root in the location you specified.

This is normal behavior unless you install a Ruby manager. I would recommend rbenv but RVM is popular as well.

These installed your Ruby installation in your $HOME folder. This way your user owns the Ruby and gem executables.

4
  • 1
    Thanks for the quick answer, I did find a work around, chown user ~/.cocoapod/master/git/FETCH_HEAD, this made my problem go away but I will look into the rbenv or RVM solution
    – godzilla
    Apr 17, 2013 at 0:44
  • 1
    for my quick workaround I also had to change permissions of ~/Library/Caches/CocoaPods/GitHub, now it works but still a hack
    – godzilla
    Apr 17, 2013 at 1:20
  • 1
    To be clear, you need to use sudo to install the gem unless you are using a Ruby manager. The other issues that you had are not expected and could have been caused by running sudo pod setup or sudo pod install.
    – Fabio
    Apr 17, 2013 at 19:30
  • Thanks Fabio, I never ran pod setup, but when I run sudo pod install it creates root owned libs which wont compile. Also update to my quick fix, I had to chown everything under ~/.cocoapod/master/git/ I tested that and it works ok. I will look into the pod setup and the Ruby manager.
    – godzilla
    Apr 17, 2013 at 22:51
4

With all the errors that I got while installing CocoaPods in some of my projects, I've finally succeeded in finding a pattern with it. Here it is:

  1. Access your project folder from the terminal:

    $ cd /Users/username/Downloads/MessagesTableViewController-master
    
  2. Create a podfile:

    $ touch podfile
    $ open -e podfile
    
  3. After the podfile is created, access it via the Finder and edit it in any other text editor except TextEdit because TextEdit sometimes messes up with apostrophes in the pod file. I used textWrangler. Write the following in the pod file; (Note these dependencies are for projects that support iOS version 6.0 and above)

    platform :ios, '6.0'
    pod 'AFNetworking'
    
  4. Save the file and close it.

  5. Go back to the terminal and see your pod version:

    $ pod --version
    

    Depending on your pod version, if an update is required, run this command:

    $ sudo gem update
    
  6. After the update completes, or it states that it is already up-to-date, you should install the cocoapods:

    $ sudo gem install cocoapods
    
  7. And at the very end, just run the following commands:

    $ sudo pod setup
    $ sudo pod install
    

And Viola! It is done. You'll see a Pods named folder within your project folder and the dependency you stated in the pod file will be apparent in Pods folder as a sub-folder.

Happy coding :)

3

It's just need to add permission flag --user-install
For updating use:
sudo gem update --user-install
And for installing use:
sudo gem install --user-install cocoapods

1
  • 1
    its work for me after add permission flag --user-install in macos ventura 13.0.1 Nov 11, 2022 at 17:48
0

Quick, easy, hacky solution:

sudo chmod -R 777 ~/.cocoapods
sudo chmod -R 777 ~/Library/Caches/CocoaPods
0

This is a known issue. There's more on the CocoaPods official web-site.

0

Answering the original question:

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

When I do a pod install I get:

Analyzing dependencies
CocoaPods 0.36.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre` 

so I assume sudo is OK.

1
  • Your use of sudo would be to install an update to cocoapods itself, which is necessary. Sudo is not okay for 'sudo pod install', as it produces the error: [!] You cannot run CocoaPods as root. Dec 19, 2018 at 16:00
0

I solved it by installing the most up to date version of Ruby. Instructions here: https://gorails.com/setup/osx/10.12-sierra I was then able to successfully run sudo gem update sudo gem install cocoapods

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.