本人也是第一次安裝這個 CocoaPods,因此剛開始也是遇到了不少懵逼的問題,今天終於搞定了,就本身總結一下,若有錯誤敬請指出,謝謝!html
因爲以前,對於終端命令行,不是很瞭解,總感受很麻煩,因此也一直沒搞CocoaPods,最近比較閒點,就試試ios
終端輸入 $ruby -v 查看ruby的版本git
打印代碼:github
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
終端輸入以下命令(把Ruby鏡像指向taobao,避免被牆,你懂得)vim
a.移除現有 Ruby 默認源輸入如下指令api
$gem sources --remove https://rubygems.org/ xcode
b.使用新的源輸入如下指令 ruby
$gem sources -a https://ruby.taobao.org/ bash
c.驗證新源是否替換成功輸入如下指令 app
$gem sources -l (用來檢查使用替換鏡像位置成功)
打印代碼:
bogon:~ LiuWenqiang$ gem sources --remove https://rubygems.org/
source https://rubygems.org/ not present in cache
bogon:~ LiuWenqiang$ gem sources -a https://ruby.taobao.org/
source https://ruby.taobao.org/ already present in the cache
bogon:~ LiuWenqiang$ gem sources -l *** CURRENT SOURCES ***
終端 $sudo gem install cocoa pods
最新插入:若是打印的是報錯信息,
ERROR: Could not find a valid gem 'cocoapod' (>= 0) in any repository
說明你尚未安裝命令行工具,執行下這個命令:
$Xcode-select --install
就會發現 彈出一個窗問咱們是否要安裝命令行工具
安裝完了後 再次sudo gem install cocoapods 發現仍是會報一樣的錯誤 百度了下 看到了這個哥們的錯誤總結,說多是權限的問題,須要進去到root下面,使用sudo -i或者sudo su進入到root以後再 執行sudo gem install cocoapods 到這裏命令行工具就安裝好了 command+q退出一下 再從新進入Shell裏面 執行sudo gem install cocoapods 會發現出來一大段
這就遇到個人第一個問題:
若是你的ruby 版本太低 就會報錯:
ERROR: Error installing cocoa: activesupport requires Ruby version >= 2.2.2. ERROR: Error installing pods: activesupport requires Ruby version >= 2.2.2.
前幾天,我就搞到這個地方,嘗試了好幾種方法更新ruby 可是都沒有成功,今天偶然看到一個文章,(有種淡淡的憂傷:http://www.jianshu.com/p/ad98a3364803
)並獲得做者的幫助,才得以解決
解決方案:
$curl -L get.rvm.io | bash -s stable
打印代碼:
In case of problems: https://rvm.io/help and https://twitter.com/rvm_io
說明安裝成功
$ source ~/.bashrc
$source ~/.bash_profile
$rvm -v
打印代碼:
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ruby -v
$rvm list known
打印代碼:
# MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-head] # security released on head [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p330] [ruby-]1.9.3[-p551] [ruby-]2.0.0[-p648] [ruby-]2.1[.8] [ruby-]2.2[.4] [ruby-]2.3[.0] [ruby-]2.2-head ruby-head # for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2
# JRuby jruby-1.6[.8] jruby-1.7[.23] jruby[-9.0.5.0] jruby-head # Rubinius rbx-1[.4.3] rbx-2.3[.0] rbx-2.4[.1] rbx[-2.5.8] rbx-head
$rvm install 2.2.2
若是打印:
…… ruby-2.2.2 - #validate archive ruby-2.2.2 - #extract ruby-2.2.2 - #validate binary ruby-2.2.2 - #setup ruby-2.2.2 - #gemset created /Users/abc/.rvm/gems/ruby-2.2.2@global ruby-2.2.2 - #importing gemset
/Users/abc/.rvm/gemsets/global.gems.............................. ruby-2.2.2 - #generating global wrappers........ ruby-2.2.2 - #gemset created /Users/abc/.rvm/gems/ruby-2.2.2 ruby-2.2.2 - #importing gemsetfile /Users/abc/.rvm/gemsets/default.gems
evaluated to empty gem list ruby-2.2.2 - #generating default wrappers........ Updating certificates in '/etc/openssl/cert.pem'. mkdir: /etc/openssl: Permission denied mkdir -p "/etc/openssl" failed, retrying with sudo LiuWenqiang password required for 'mkdir -p /etc/openssl': and sudo mkdir worked
則說明安裝成功了
打印代碼:
Done with Command Line Tools (OS X 10.11) for Xcode Done. ==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress ==> Installing the Command Line Tools (expect a GUI popup): ==> /usr/bin/sudo /usr/bin/xcode-select --install xcode-select: error: command line tools are already installed, use "Software Update" to install updates Failed during: /usr/bin/sudo /usr/bin/xcode-select --install Requirements installation failed with status: 1.
若是安裝失敗
第二個問題:
解決方案:
$ sudo xcode-select --switch /Library/Developer/CommandLineTools/
Password: (輸入電腦權限密碼)
$ git
usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>]
第二個問題就解決了
而後再從新執行:安裝2.2.2版本 步驟 就能夠解決
(5)查看當前ruby 版本
$ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
如今ruby版本已是2.2.2了
第一個問題就解決了
$sudo gem install cocoa pods
$sudo gem install -n /usr/local/bin cocoapods
$pod setup
$sudo gem update --system
cd /Users/lucky/Desktop/PodTest
$vim Podfile
鍵盤輸入 i 進入編輯模式,輸入
platform :ios, '7.0'
pod 'MBProgressHUD', '~> 0.8’ (以前的,個人電腦上已經無效了,報錯: [!] The dependency `MBProgressHUD (~> 0.8)` is not used in any concrete target.)
(如今使用:MyApp 替換成本身的項目名)
target 'MyApp' do
pod 'AFNetworking', '~> 2.6'
pod 'ORStackView', '~> 3.0'
end
而後按Esc,而且輸入「 :」號進入vim命令模式,而後在冒號後邊輸入wq
再輸入 $pod install
注意:如今打開項目不是點擊 PodTest.xodeproj了,而是點擊 PodTest.xcworkspace
爲了肯定AFNetworking是否支持CocoaPods,能夠用CocoaPods的搜索功能驗證一下。在終端中輸入:
$ pod search AFNetworking
(文中的$ 符號 是表示在終端輸入的意思,符號自己不用添加終端)
參考資料來源:(謝謝這些做者)
http://blog.csdn.net/showhilllee/article/details/38398119
http://blog.csdn.net/zhaojinqiang12/article/details/51682191
若是還有其餘問題,給你推薦這篇文章,該做者會按期更新:
http://www.jianshu.com/p/6e5c0f78200a