1.检查ruby源:gem sources -l;
如果是
*** CURRENT SOURCES ***
当然这个源在墙内是访问不到的。因此我们需要寻找一个可以在国内访问到的镜像。
2.删除原来的ruby源:gem sources --removehttps://rubygems.org/
注:如果出现source https://rubygems.org not present in cache情况,尝试用
sudo gem sources -rhttps://rubygems.org/命令删除
3.添加可用的镜像源:gem sources -ahttps://gems.ruby-china.org
注:如果出现ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/Apple/.gemrc情况,尝试用
sudo gem sources -ahttps://gems.ruby-china.org命令添加
使用gem sources -l查看是否添加成功,如果打印出
*** CURRENT SOURCES ***
表示添加成功
4.下载和安装CocoaPods: sudo gem install -n /usr/local/bin cocoapods
注:如果出现Fetching: activesupport-5.0.0.1.gem (100%)ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
则用sudo gem install cocoapods命令:
如果出现ERROR: Error installing cocoapods:
activesupport requires Ruby version >= 2.2.2.情况,则调用
curl -L get.rvm.io | bash -s stable命令安装RVM baby版本管理器,
//________等安装完成 出现下面这行提示以下___________
In case of problems: https://rvm.io/helpandhttps://twitter.com/rvm_io
执行:$source ~/.bashrc
$source ~/.bash_profile
测试是否安装正常:$rvm -v
//________提示以下___________
rvm 1.27.0 (latest) by Wayne E. Seguin, Michal Papis[https://rvm.io/]
用RVM升级Ruby查看当前ruby版本:$ruby -v
$rvm list known
安装ruby 2.2.2 执行:rvm install 2.2,如果有提示:Ruby was built without documentation, to build it run: rvm docs generate-ri则调用Apple$ rvm docs generate-ri命 令,最后调用sudo gem install cocoapods再次安装cocoapods
5、更新Podspec索引文件,创建本地索引库(这里要多等一会儿)
pod setup
如果更新成功,就不用执行6和7步骤
6.安装成功后,Apple$ pod search Afnet测试,如果出现Setting up CocoaPods master repo卡住现象:
解决方法:Apple$ pod repo remove master
Apple$ git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master
Apple$ pod repo update
7.搜索库文件:Apple$ pod search Afnet
如果出现[!] Unable to find a pod with name, author, summary, or descriptionmatching `Afnet`情况:
解决方法:Apple$ pod setup 此方法如果不行
则执行Apple$ rm ~/Library/Caches/CocoaPods/search_index.json命令
8、进入项目目录
cd ~
9、创建Podfile文件
touch Podfile
10.打开工程文件,导入pod:
Apple$ cd /Users/Apple/Documents/xmTest/Test
Apple$ vim Podfile:格式如下
platform:ios, '7.0'
target 'Test' do//其中Test为项目名
pod 'AFNetworking', '~> 3.1.0'
end
11.安装:Apple$ pod install