Saturday, February 4, 2017

After updating Xcode / after updating to MacOS Sierra, my pod installation got wiped out.

I get this error every time I try and run
sudo gem install cocoapods
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj

I followed the following procedure.

Installing CocoaPods on OS X 10.11 and macOS 10.12

These instructions were tested on all betas and the final release of El Capitan, also on betas of Sierra.

Custom GEM_HOME

This is the solution when you are receiving the "Operation not permitted" error.
$ mkdir -p $HOME/Software/ruby
$ export GEM_HOME=$HOME/Software/ruby
$ gem install cocoapods
[...]
1 gem installed
$ export PATH=$PATH:$HOME/Software/ruby/bin
$ pod --version
0.37.2

Standard system installation

For whatever reason, the rootless stuff seems less restrictive when one simply upgrades the system. I could sudo gem install cocoapods just fine on a machine upgraded from 10.10 - however, binstubs are no longer installed into /usr/bin:
$ sudo gem install cocoapods
[...]
1 gem installed
$ export PATH=$PATH:/Library/Ruby/bin
$ pod --version
0.37.2
We have heard from some users that they receive this error when doing a system-wide installation:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
This happens when you have updated the rubygems gem of your system ruby installation, but this can be solved by passing -n /usr/local/bin to the install command, so that the pod executable gets installed there. The issue here is that the default gem that ships with the system has a customised binary directory, but any newer version you install (e.g. via gem update --system) does not.
Note: I've locked the issue to collaborators so that these instructions don't get buried for now.