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文件。