一.更改镜像:
1.查看当前的镜像,在终端输入:gem sources -l
结果:
*** CURRENT SOURCES ***
https://rubygems.org/
2.删除当前镜像,在终端输入:gem sources --remove https://rubygems.org/
结果:https://rubygems.org/ removed from sources
3.添加阿里镜像,在终端输入:gem sources -a http://rubygems-china.oss.aliyuncs.com
4.查看当前的镜像,在终端输入:gem sources -l
结果:
*** CURRENT SOURCES ***
http://rubygems-china.oss.aliyuncs.com
表示更换成功。
二.安装Cocoapods:
1.终端输入:sudo gem install cocoa pods
如果出现以下错误:
“Error installing cocoapods: activesupport requires Ruby version >= 2.2.2.”
则要更新ruby步骤如下(都是在终端输入):
1.curl -L get.rvm.io | bash -s stable
结果:“In case of problems: https://rvm.io/helpandhttps://twitter.com/rvm_io”
2.source ~/.bashrc
3.source ~/.bash_profile
4.rvm -v
结果:“rvm 1.27.0 (latest) by Wayne E. Seguin, Michal Papis[https://rvm.io/]”
5.ruby -v
6.查看当前所有的版本: rvm list known
7.升级到2.2.2版本: rvm install 2.2.2
8.sudo gem update --system
9.sudo gem install cocoa pods
结果:“........ 73 gems installed”
表示安装成功。
三.下载Cocoapods依赖包
1.pod repo remove master
2.git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
3.pod repo update
四.使用Cocoapods
1.终端中输入:cd空格把项目拖入空格后面
如:MacBook-Pro:~ mac$ cd /Users/mac/Desktop/test
2.pod init
3.编写Podfile文件
如添加'AFNetworking'和‘SDWebImage’框架:
platform :ios, '9.0'
target 'test' do
pod 'AFNetworking'
pod 'SDWebImage'
end
4.pod install
结果:"Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed."
恭喜你可以正常使用了!