安装Cocoapods时候ERROR: While executing gem ... (Errno::EPERM)

OS X 10.11 安装Cocoapods 出现问题的解决方法 
今天尝试用 Cocoapods安装个第三方库.. 输入pod install, 发现 command not find。 WTF!

估计是升级10.11后Cocoapods被干掉了。

我输入 sudo gem install cocoa pods 之后,出现如下问题:

ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/xcodeproj
  • 1
  • 2

我估计是gem版本没有更新。执行sudo gem update –system,又出现了错误

ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/update_rubygems
  • 1
  • 2

Stackoverflow上找到了解决方法:

因为知道gem版本过老的话也是不能成功下载cocoapods的,但是我现在又不能用sudo gem update –system来更新。后来我就直接去rubygems官网下载了最新的源码进行了安装。现在执行gem -v显示版本是2.4.8。 
可以看我另外一篇文章,手动安装gem

可是问题又来了,这个时候去执行sudo gem install cocoapods,还是会出现上边的错误。 
所以执行下边:

自定义GEM_HOME
$ 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.38.2
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

GEM_PATH与GEM_HOME 的区别:

1.GEM_PATH provides the locations (there may be several) where gems can be found. 
2.GEM_HOME is where gems will be installed (by default).(Therefore GEM_PATH should include GEM_HOME).

但是之后我pod install的时候又花式出错

[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master`.
You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
  • 1
  • 2

我尝试按提示的方法

pod repo add master https://github.com/CocoaPods/Specs.git
  • 1

然而还是有错..

[!] /usr/bin/git clone http://git.oschina.net/akuandev/Specs.git master

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  • 1
  • 2
  • 3

最后的解决方法:

sudo xcode-select -switch /Applications/Xcode-beta.app/Contents/Developers
  • 1

后面的地址你可以打开Xcode显示包内容,找到那个文件夹拖到终端里面比较不容易错。

最后终于修成正果..

至于一开始输入 sudo gem install cocoapods 没反应需要修改为淘宝镜像的问题,请百度Cocoapods参阅其它文章..

posted @ 2016-08-08 10:04  jgCho  阅读(5643)  评论(0编辑  收藏  举报