Cocoapods commands fail due to "No such file or directory @ dir_initialize - /Users/<username>/.cocoapods/repos (Errno::ENOENT)"

Solution 1:

If the message says you are missing a lib:

I got same problem and it was fixed after running pod setup and then pod install

If the missing directory is the ruby dir you can do:

You have probably updated your osx or ruby gem recently and its PATH is still linking to the old ruby version. Fix with:

sudo gem install -n /usr/local/bin ruby

sudo gem install -n /usr/local/bin cocoapods

As said by @rendel

Solution 2:

Cocoapods had an issue where their github repository had become corrupted, and this forces users to clean up their local repo manually.

A quote from the Cocoapods blog post detailing the error:

Unfortunately we've encountered a bug in libgit2 and we are going to have to force push into the Specs repository. (Also known as the ‘master’ spec repo.)

What does this mean for you? Well, basically your CocoaPods setup is going to break. You are going to have to manually delete any local copies of the Specs repository and re-clone the new version of the Specs repository. You can do that with the following commands:

The Solution:

$ sudo rm -fr ~/.cocoapods/repos/master
$ pod setup

Simply running the commands above will remove the corrupted repo and reinitialize using a clean repo. See the blogpost mentioned above for more information.

Hope this helps!