1.开启 terminal
2.移除现有 Ruby 默认源
$ gem sources --remove https://rubygems.org/
3.使用新的源
$ gem sources -a https://ruby.taobao.org/
4.验证新源是否替换成功
$ gem sources -l
只有在终端中出现下面文字才表明你上面的命令是成功的:
***CURRENT SOURCES***
http://ruby.taobao.org/
5.安装cocoapods
$ sudo gem install cocoapods
这个时候可能会提示你需要升级ruby,正确的安装是这样的:
CHANGELOG:
## 0.32.1
##### Bug Fixes
* Fixed the Podfile `default_subspec` attribute in nested subspecs.
[Fabio Pelosin][irrationalfab]
\ [#2050](https://github.com/CocoaPods/CocoaPods/issues/2050)
Successfully installed cocoapods-0.32.1
Installing ri documentation for cocoapods-0.32.1
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block
Done installing documentation for cocoapods after 10 seconds
1 gem installed
6.执行pod install 命令
$ pod install
出现Setting up CocoaPods master repo,说明Cocoapods在将它的信息下载到 ~/.cocoapods里;
cd 到该目录里,用du -sh *命令来查看文件大小,每隔几分钟查看一次,这个目录最终大小是300多M,就是完成了
7.使用cocoapods
新建ios工程项目,cd 到 xxx.xcodeproj目录下创建Podfile文件
$ touch Podfile
编辑Podfile文件
$ vim Podfile
最新CocoaPods的版本v1.0.1 要求Podfile的写法如下:
platform:ios,'7.0'
target "MyProject" do
pod 'MJRefresh', '~> 3.1.0'
pod 'SDWebImage', '~> 3.7.6'
pod 'SVProgressHUD', '~> 2.0.3'
pod 'AFNetworking', '~> 3.1.0'
end
然后保存退出。vim环境下,保存退出命令是:
:wq
$ pod install
运行上述命令之后,小编的终端出现以下信息:
EricmatoMacBook-Pro:CocoaPodsDemo ericwang$ podinstallAnalyzing dependenciesDownloading dependenciesInstalling AFNetworking (2.0.2)Generating Pods projectIntegrating client project[!]Fromnowonuse`CocoaPodsDemo.xcworkspace`.
注意最后一句话,意思是:以后打开项目就用xxx.xcworkspace 打开,而不是之前的.xcodeproj文件。