1.打開終端
2.移除現有 Ruby 默認源 輸入以下指令
$gem sources --remove https://rubygems.org/
3.使用新的源 輸入以下指令
$gem sources -a https://ruby.taobao.org/
4.驗證新源是否替換成功 輸入以下指令
$gem sources -l
5.安裝 CocoaPods
$sudo gem install cocoa pods
//–––––––––––那么問題來了——沒遇到的自動跳過————————————
錯誤提示1
Error installing cocoapods: activesupport requires Ruby version >= 2.2.2.
解決方案 :
1、安裝 RVM baby 版本管理器
$curl -L get.rvm.io | bash -s stable
//________等安裝完成 出現下面這行提示以下___________
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/]
2、用RVM升級Ruby查看當前ruby版本
$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-headruby-head # for forks use: rvm install ruby-head---url https://github.com/github/ruby.git --branch 2.2 # JRuby
安裝ruby 2.2.2 執行
$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.
4. 繼續安裝 CocoaPods
$sudo gem install cocoa pods $sudo gem install -n /usr/local/bin cocoapods $pod setup
5. 更新 gem
$sudo gem update --system
6. 新建一個項目,名字PodTest
7. $ cd 項目路徑 (中間有空格,)
cd /Users/lucky/Desktop/PodTest
8. 建立Podfile(配置文件)
$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
###如果安裝失敗
干貨1:
安裝ruby遇到" Installing Homebrew - Brew Command Not Found"命令找不到解決方案:
Check XCode is installed or not.
$gcc --version $ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" $brew doctor $brew update.
完成后 執行
$ruby -v
//–––––打印輸出––––––– ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
6 繼續安裝 CocoaPods
$sudo gem install cocoa pods
//______安裝成功提示如下______ Done installing documentation for nap, fourflusher, escape, colored, concurrent-ruby, thread_safe, tzinfo, i18n, activesupport, claide, xcodeproj, molinillo, cocoapods-try, netrc, cocoapods-trunk, cocoapods-stats, cocoapods-search, cocoapods-plugins, cocoapods-downloader, cocoapods-deintegrate, fuzzy_match, cocoapods-core, cocoapods after 21 seconds,23 gems installed
$pod setup
備注:蘋果系統升級 OS X EL Capitan 后安裝改為:
$sudo gem install -n /usr/local/bin cocoapods
$pod setup
干貨2:
CocoaPods無限卡在Setting up CocoaPods master repo解決方案:
對於初次使用CocoaPods的同學,即使你不使用pod setup命令,在你初次執行pod install命令時,系統也會自動執行pod setup。而由於網絡不穩定的原因,不掛VPN是不可能成功執行pod setup的。(我大天朝的牆啊~~~~)
$ pod repo remove master $ git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master $ pod repo update
7 更新 gem
$sudo gem update --system
8 新建工程,並在終端用 cd 指令到文件夾內
$pod search 第三方庫
9 新建 Podfile 文件
$ touch Podfile
10 編輯 Podfile 文件,並寫入要添加的第三方庫(cocoapod1.0.1版本Podfile文件的內容格式要求發生了變化,必須指出指出所用第三方庫的target)
platform:ios, '8.0' #use_frameworks!個別需要用到它,比如reactiveCocoa target 'XXXApp' do pod 'AFNetworking', '2.3.1'<-------第三方 end
11 導入第三方庫
$pod install --no-repo-update
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. 此時查詢Xcode,切換到另一個環境: $ 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>]
ERROR: Error installing cocoapods: activesupport requires Ruby version >= 2.2.2. localhost:~ zzz$ $curl -L get.rvm.io | bash -s stable -bash: -L: command not found localhost:~ zzz$
解決方法:
ruby -e "$(wget -qO - 'https://raw.github.com/mxcl/homebrew/go')" $ 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>]