1、升级Ruby环境
sudo gem update --system
这是因为你没有权限去升级Ruby
这时应该输入:$ sudo gem update --system
此时会出现

如果失败
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem
则执行
sudo gem install -n /usr/local/bin cocoapods

恭喜你,Ruby升级成功!
2、更换Ruby镜像
首先移除现有的Ruby镜像
终端输入:$ gem sources --remove https://rubygems.org/
然后添加国内最新镜像源(淘宝的Ruby镜像已经不更新了)
终端输入:$ gem sources -a https://gems.ruby-china.com/
执行完毕之后输入gem sources -l来查看当前镜像
终端输入:$ gem sources -l
如果结果是
*** CURRENT SOURCES ***
https://gems.ruby-china.com
说明添加成功,否则继续执行$ gem source -a https://gems.ruby-china.org/来添加
3、安装CocoaPods
终端输入:$ sudo gem install cocoapods


如果出现:
While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
改为 sudo gem install -n /usr/local/bin cocoapods
到这之后再执行pod setup(PS:这个过程是漫长的,要有耐心)
终端输入:
$ pod setup
如果出现了这个错误

别慌,执行下面的
$ sudo rm -fr ~/.cocoapods/repos/master
$ pod setup
$ pod install
出现Setup completed的时候说明已经完成了
如何使用参考:https://www.cnblogs.com/chuancheng/p/8443677.html
网友评论