CocoaPods最新最全安裝教程

1>. 升級gem

sudo gem update --system

2>. 移除現有 Ruby 默認源

gem sources --remove https://rubygems.org/

3>. 使用國內鏡像源

gem sources -a https://gems.ruby-china.com/

4>. 驗證當前鏡像源

gem sources -l

5>. 安裝cocoapods

 系統升級 OS X EL Capitan 前:sudo gem install cocoapods
 系統升級 OS X EL Capitan 后:sudo gem install -n /usr/local/bin cocoapods

6>. 如果步驟5成功則執行pod setup,成功后執行pod -version 檢查版本

 如果失敗,比如:Error installing cocoapods:  activesupport requires Ruby version >= 2.2.2. 則說明當前的ruby版本低于2.2.2,然后進行第7.

7>. 安裝 RVM (ruby 版本管理器)

curl -L get.rvm.io | bash -s stable
//________等安裝完成 出現下面這行提示以下___________
In case of problems: https://rvm.io/helpandhttps://twitter.com/rvm_io

8>. 執行

$source ~/.bashrc  
$source ~/.bash_profile  

9>. 檢查rvm版本,看是否安裝成功

rvm -v 
//________提示以下___________
rvm 1.27.0 (latest) by Wayne E. Seguin, Michal Papis[https://rvm.io/]

10>. 使用rvm查看管理的所有ruby版本

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

11>. 升級ruby

rvm install 2.2.2

12>. 安裝homebrew

情形1:
//________提示以下___________
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.11/x86_64/ruby-2.3.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
About to install Homebrew, press `Enter` for default installation in `/usr/local`,
type new path if you wish custom Homebrew installation (the path needs to be writable for user) 
如果出現以上信息可以直接回車,會安裝homebrew相關的管理工具。

情形2:
//________提示以下___________
Error running 'requirements_osx_brew_update_system ruby-2.3.0',
showing last 15 lines of /Users/peter/.rvm/log/1481169271_ruby-2.3.0/update_system.log
https://github.com/Homebrew/homebrew/wiki/Common-Issues
++ rvm_pretty_print stderr
++ case "${rvm_pretty_print_flag:=auto}" in
++ case "${TERM:-dumb}" in
++ case "$1" in
++ [[ -t 2 ]]
++ printf %b 'Failed to update Homebrew, follow instructions here:
https://github.com/Homebrew/homebrew/wiki/Common-Issues
and make sure `brew update` works before continuing.\n'
Failed to update Homebrew, follow instructions here:
https://github.com/Homebrew/homebrew/wiki/Common-Issues
++ return 1
Requirements installation failed with status: 1.
如果出現以上信息可以執行命令:ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
附homebrew官網:http://brew.sh/index_zh-cn.html

13>. 等12步homebrew安裝完后再執行

rvm install ruby-2.3.0
//________成功提示___________
ruby-2.3.0 - #extracting ruby-2.3.0 to /Users/Peter/.rvm/src/ruby-2.3.0....
ruby-2.3.0 - #configuring......................................................|
ruby-2.3.0 - #post-configuration.
ruby-2.3.0 - #compiling........................................................|
ruby-2.3.0 - #installing.........
ruby-2.3.0 - #making binaries executable..
Installed rubygems 2.5.1 is newer than 2.4.8 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.3.0 - #gemset created /Users/Peter/.rvm/gems/ruby-2.3.0@global
ruby-2.3.0 - #importing gemset /Users/Peter/.rvm/gemsets/global.gems...........|
ruby-2.3.0 - #generating global wrappers........
ruby-2.3.0 - #gemset created /Users/Peter/.rvm/gems/ruby-2.3.0
ruby-2.3.0 - #importing gemsetfile /Users/Peter/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.3.0 - #generating default wrappers........
ruby-2.3.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.3.0 - #complete 
Ruby was built without documentation, to build it run: rvm docs generate-ri

//________錯誤提示___________
There was an error(56).
Checking fallback: https://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
No fallback URL could be found, try increasing timeout with:

echo "export rvm_max_time_flag=20" >> ~/.rvmrc

There has been an error fetching the ruby interpreter. Halting the installation.
解決辦法:版本號只保留2位,改為命令rvm install 2.3即可

14>. 檢查ruby版本

ruby -v
//________成功提示___________
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]

15>. 執行

sudo gem install -n /usr/local/bin cocoapods
//________提示___________
Fetching: nanaimo-0.2.3.gem (100%)
Successfully installed nanaimo-0.2.3
Fetching: colored-1.2.gem (100%)
Fetching: claide-1.0.1.gem (100%)
Successfully installed claide-1.0.1
Fetching: CFPropertyList-2.3.4.gem (100%)
Successfully installed CFPropertyList-2.3.4
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
...
Successfully installed cocoapods-plugins-1.0.0
Fetching: cocoapods-downloader-1.1.2.gem (100%)
Successfully installed cocoapods-downloader-1.1.2
Fetching: cocoapods-deintegrate-1.0.1.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.1
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.1.1.gem (100%)
Successfully installed cocoapods-core-1.1.1
Fetching: cocoapods-1.1.1.gem (100%)
ERROR:  While executing gem ... (TypeError)
no implicit conversion of nil into String

16>. 上邊出錯后更新gem

gem update --system 
//________成功提示___________
RubyGems system software updated

17>. 再執行

sudo gem install -n /usr/local/bin cocoapods

18>. 執行

pod setup

19>. 如果出現下面問題:

Setting up CocoaPods master repo
[!] /usr/local/bin/Git clone https://github.com/CocoaPods/Specs.git master

Cloning into 'master'...
error: RPC failed; curl 56 SSLRead() return error -36
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

依次執行:
sudo gem uninstall cocoa pods
pod repo remove master
sudo gem install -n /usr/local/bin cocoa pods
pod setup

20>. 如果第19步沒有問題,表示安裝OK,會看到如下信息

CocoaPods 1.2.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.2.0.beta.1

Setup completed

21>. 再檢查版本

pod --version
出現:1.1.1

到此安裝步驟全部完成!!!以上是我的安裝步驟,也可以參照:http://blog.csdn.net/sharktoping/article/details/52311460

如果看不到最新版本,請使用 pod repo update 命令更新一下本地pod倉庫

pod另一現象和解決辦法

現象:[!] Unable to find a pod with name, author, summary, or description matching `YYkit`
解決辦法: rm ~/Library/Caches/CocoaPods/search_index.json
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • CocoaPods 是什么? CocoaPods 是一個負責管理 iOS 項目中第三方開源庫的工具。CocoaPo...
    朝洋閱讀 25,744評論 3 50
  • 第一次安裝CocoaPods也遇到了一些坑,但是 那個時候時間比較緊,沒有抽出時間整理,最近因為電腦還原從新做了系...
    幸福的尾巴__閱讀 8,373評論 7 9
  • 有人講 愛情本來就是俗套的事 誰也不想自己是白開水 毫無吸收價值 喝下去是一杯 尿出來還是一杯 我們總是在被愛中分...
    人生本來如寄閱讀 567評論 0 2
  • 去一個地方當教師招聘的面試評委,坐在評委席上,我仿佛看到自己當年面試時青澀的樣子。幾十個考生看過,我終于明白,當年...
    董余蘭閱讀 1,907評論 2 3
  • 愛從眼角出發,奔向鬢角。 這貌似很短的距離,卻需要一生的跋涉才能抵達,最終變成心疼和牽掛。 前段時間看慣了娛樂圈的...
    小紅豆兒閱讀 376評論 0 3