一、概要
iOS開發時,項目中會引用許多第三方庫,CocoaPods(https://github.com/CocoaPods/CocoaPods)可以用來方便的統一管理這些第三方庫。
二、安裝
由於網上的教程基本都大同小異,但細節之處還不是很完善,所以藉機會在這裡補充下:
註:要使用CocoaPods,那就要下載安裝它,而下載安裝CocoaPods需要Ruby環境
1、Ruby環境搭建
當前安裝環境為Mac mini 10.8.5。Mac OS本身內建Ruby,但還是更新一下保險,因為我第一次安裝在沒有更新Ruby的情況下就失敗了。
a 查看下當前ruby版本:開啟終端輸入 ruby -v(確實安裝了,不過用這個版本接下來工作失敗了,所以更新下ruby)
[objc] view plain copy print ? ritekiMac-mini:PodTest lucky$ ruby -v ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] ritekiMac-mini:PodTest lucky$
b 更新ruby
終端輸入如下命令(把Ruby鏡像指向taobao,避免被牆,你懂得)
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l (用來檢查使用替換鏡像位置成功)
[objc] view plain copy print ? ritekiMac-mini:~ lucky$ gem sources --remove https://rubygems.org/ https://rubygems.org/ removed from sources ritekiMac-mini:~ lucky$ gem sources -a https://ruby.taobao.org/ https://ruby.taobao.org/ added to sources ritekiMac-mini:~ lucky$ gem sources -l *** CURRENT SOURCES ***
2、下載安裝 CocoaPods
終端輸入:sudo gem install cocoapods
[html] view plain copy print ? ritekiMac-mini:~ lucky$ sudo gem install cocoapods 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
這樣就下載安裝好了CocoaPods
3、使用CocoaPods
a 建立一個項目,名字PodTest