cocoapods安裝步驟及常見問題解決
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 -r
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