打开终端添加以下命令
首先先查看源地址是否可用,这边是用的ruby-china源是可以的。
gem sources -l // 查看源列表
gem sources -remove https://ruby.taobao.org/ // 将不需要的源移除掉
gem sources -a http://gems.ruby-china.org/ // 添加ruby-china源源(当然你有其他可用的源也可以)
sudo gem install cocoapods // 安装cocoapods
输入完之后可能需要输入用户密码,输入密码后按回车即可。
Password:
剩下的就是下载了,可能需要等待许久时间,正常情况会出现类似命令
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: cocoapods-core-1.0.0.beta.8.gem (100%)
Successfully installed cocoapods-core-1.0.0.beta.8
Fetching: claide-1.0.0.beta.3.gem (100%)
Successfully installed claide-1.0.0.beta.3
Fetching: cocoapods-deintegrate-1.0.0.beta.1.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.0.beta.1
Fetching: cocoapods-downloader-1.0.0.beta.3.gem (100%)
如果最后出现类似,则说明环境安装成功,接下来就可以使用CocoaPods来做自己想做的事情了。
Successfully installed cocoapods-1.4.0
Parsing documentation for cocoapods-1.4.0
Done installing documentation for cocoapods after 3 seconds
1 gem installed
可能你安装过程中也会出现问题:
1.源的问题
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
Unable to download data from http://ruby.taobao.org/ - bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz)
则需要替换源 http://gems.ruby-china.org/ 、https://ruby.taobao.org/
- 如果安装或更新版本出现以下问题
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
则需要使用以下命令安装
sudo gem install -n /usr/local/bin cocoapods
下边给出安装时候碰到的其他问题链接:https://stackoverflow.com/questions/32810808/can-not-perform-pod-install-under-el-capitan-15a279b
环境更新与安装时候步骤类似,不过不懂请点这里。
如果还碰到什么问题,可以留言。