【iOS工具】rvm、Ruby環境和CocoaPods安裝使用及相關報錯問題解決(2016 12 15 更新)

苜蓿九少發表於2017-12-13

〇、前言

在iOS開發中 [CocoaPods](https://github.com/CocoaPods/CocoaPods) 作為庫依賴管理工具就是一把利器。

有了 CocoaPods 則無需再通過拖 第三方庫 及第三方庫所依賴的 framework 靜態庫到專案中等麻煩的操作,僅僅只需要通過終端(Terminal)輸入一些指令即可完成這些操作;而且涉及到第三方庫的更新升級也可以通過 CocoaPods 進行手動管理更新。

方便快捷!趕快行動起來吧!!!

一、Homebrew、Rvm、Ruby、CocoaPods 簡介

  • 1、官網及相關連結

Rvm 官網 : https://www.rvm.io/ Ruby 官網 :https://rubygems.org/ CocoaPods 官網 :https://cocoapods.org/ Rvm 安裝指南 :https://rvm.io/rvm/install Homebrew 官網 :http://brew.sh/index_zh-cn.html ruby 映象 - taobao:https://ruby.taobao.org/ ruby 映象 - china:https://gems.ruby-china.org/

  • 2、Homebrew 介紹

    • Homebrew 是一個軟體包管理器,用於在mac上安裝一些os x上沒有的UNiX工具;類似於360軟體管理器。
  • 3、Rvm 介紹

    • Rvm 全稱 Ruby Version Manager ,是安裝和管理 ruby 的一種工具。
    • 摘錄:RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
  • 4、Ruby 介紹

    • Ruby 是一種物件導向的指令碼語言,簡單易用,功能強大。能跨平臺和可移植性好等等。其實就是種指令碼語言。
    • Ruby 的軟體源使用的是亞馬遜的雲服務,國內網路環境下載時可能會出現各種不穩定和超時,所以自帶的需要翻牆,可以將 官方 ruby 源 替換成國內 淘寶 ruby 源ruby.taobao.org/ )或者是由 China ruby 源gems.ruby-china.org/ )。據訊息瞭解,2016.06 淘寶源 暫停維護了,建議使用 China ruby 源
  • 5、CocoaPods 介紹

    • CocoaPods 是 iOS 最常用的第三方類庫管理工具,絕大部分有名的開源類庫都支援 CocoaPods
    • CocoaPods 是用 ruby 實現的,要想使用它首先需要有 ruby 的環境。幸運的是OS X系統預設已經可以執行 ruby 了。但是有時候 ruby 版本過低是無法正常支援 CocoaPods 的使用,所以需要先安裝更新升級 rvmruby

二、CocoaPods 安裝使用

  • 1、檢查安裝 rvm 環境( 正常情況可直接略過此步驟 )

    • 檢查當前 rvm 環境( 此處檢查是否存在 rvm 環境 ):
$ rvm -v
複製程式碼
複製程式碼

輸出結果:( 存在 rvm 環境) muxuguixiandeMacBook-Pro:~ jijiucheng$ rvm -v rvm 1.27.0 (latest) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]

複製程式碼

輸出結果:(不存在 rvm 環境) muxuguixiandeMacBook-Pro:~ jijiucheng$ rvm -v -bash: rvm: command not found


  - **情況一**:如果不存在 `rvm` 環境,先安裝配置 `rvm` 環境;
複製程式碼

① 期間可能會問你 sudo管理員 密碼,以及自動通過 homebrew 安裝依賴包; 等待一段時間後就可以成功安裝好 rvm

複製程式碼

$ curl -L https://get.rvm.io | bash -s stable

>```
輸出結果:(下載安裝)(顯示的 `` 代表一行空格)
muxuguixiandeMacBook-Pro:~ jijiucheng$ curl -L https://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current Dload  Upload   Total   Spent    Left  Speed
100   184  100   184    0     0     93      0  0:00:01  0:00:01 --:--:--    93
100 22865  100 22865    0     0   8964      0  0:00:02  0:00:02 --:--:--  710k
Downloading https://github.com/rvm/rvm/archive/1.27.0.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc',
but no GPG software exists to validate it, skipping.
``
`Installing RVM to /Users/smalllufeinj/.rvm/`
    Adding rvm PATH line to /Users/smalllufeinj/.profile /Users/smalllufeinj/.mkshrc /Users/smalllufeinj/.bashrc /Users/smalllufeinj/.zshrc.
    Adding rvm loading line to /Users/smalllufeinj/.profile /Users/smalllufeinj/.bash_profile /Users/smalllufeinj/.zlogin.
`Installation of RVM in /Users/smalllufeinj/.rvm/ is almost complete:`
``
  .* To start using RVM you need to run `source /Users/smalllufeinj/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
``
# muxuguixian,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.
``
In case of problems: https://rvm.io/help and https://twitter.com/rvm_io
複製程式碼

下載安裝 rvm 環境.png

  • 複製程式碼

② 然後,載入 RVM 環境(新開 Termal 就不用這麼做了,會自動重新載入的)。

複製程式碼

$ source ~/.rvm/scripts/rvm

>```
輸出結果:(^_^)(什麼都沒有輸出)
muxuguixiandeMacBook-Pro:~ jijiucheng$ source ~/.rvm/scripts/rvm
複製程式碼
  • 複製程式碼

③ 再次檢查 rvm 是否安裝正確。

複製程式碼

$ rvm -v

>```
`輸出結果:( 存在 rvm 環境)`
muxuguixiandeMacBook-Pro:~ jijiucheng$ rvm -v
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
複製程式碼
  • 情況二:如果存在 rvm 環境,用 rvm 安裝 ruby 環境;
  • ruby 版本低於 2.2.2 時,安裝 CocoaPods 會報錯;為防止 ruby 版本過低,建議先升級 ruby 環境,建議升級到 2.3.0 版本以上。【可以通過 $ ruby -v 指令檢查當前 ruby 版本】
  ① 查詢已知的 ruby 環境。
複製程式碼
$ rvm list known
複製程式碼
複製程式碼

輸出結果:(顯示的 `` 代表一行空格) muxuguixiandeMacBook-Pro:~ jijiucheng$ 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- --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 ``

Opal

opal ``

Minimalistic ruby implementation - ISO 30170:2012

mruby[-head] ``

Ruby Enterprise Edition

ree-1.8.6 ree[-1.8.7][-2012.02] ``

GoRuby

goruby ``

Topaz

topaz ``

MagLev

maglev[-head] maglev-1.0.0 ``

Mac OS X Snow Leopard Or Newer

macruby-0.10 macruby-0.11 macruby[-0.12] macruby-nightly macruby-head ``

IronRuby

ironruby[-1.1.3] ironruby-head

![查詢已知的 ruby 環境 .png](http://upload-images.jianshu.io/upload_images/711060-1368757fe3502d2d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

  - ```
② 指定 ruby 版本進行更新( 此處按照 ruby 2.3.0 版本進行更新 )。
複製程式碼
$ rvm install 2.3.0
複製程式碼
複製程式碼

輸出結果:( 此處因為終端輸出的字元過多,所以此處用截圖方式 )

![指定 ruby 版本進行更新 .png](http://upload-images.jianshu.io/upload_images/711060-7befae589754d80a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

  - ```
③ 第二步需要一段時間等待,完成後此時 rvm 環境就配置好了;Ruby Gems 就安裝好了。
複製程式碼
④ 補充相關指令:
複製程式碼

查詢已安裝的 ruby:

$ rvm list
複製程式碼

解除安裝一個已安裝版本:

$ rvm remove 1.9.2
複製程式碼
  • 2、檢查更新 ruby 版本環境(正常情況下從此步驟開始)

    • CocoaPods 是用 gem ruby 實現的,要想使用它首先需要有 gem ruby 的環境。且 MAC 的 OS X系統預設已經可以執行 ruby
    • 此處建議 gem ruby 包環境升級到 2.6.x 以上。
    • 檢查 gem ruby 版本號:
$ sudo gem -v
複製程式碼
複製程式碼

檢查結果:( 預設情況下版本應該較低,建議升級到 ) muxuguixiandeMacBook-Pro:local jijiucheng$ gem -v 2.5.1


  - 更新 `gem ruby` 版本號:
複製程式碼

$ gem update --system

> ```
更新成功:( 實際列印可能與此不同,但是成功了就會顯示 Successfully )
muxuguixiandeMacBook-Pro:local jijiucheng$ gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.6.7.gem (100%)
Successfully installed rubygems-update-2.6.7
複製程式碼
此種提示:( 表示已經是最新的 gem ruby 環境 )
muxuguixiandeMacBook-Pro:~ jijiucheng$ gem update --system
Latest version currently installed. Aborting.
複製程式碼
  • 檢查 ruby 源
$ gem sources -l
複製程式碼
複製程式碼

檢查結果:( 如果電腦沒安裝過 CocoaPods,此時應該是預設 ruby 源 ) muxuguixiandeMacBook-Pro:~ jijiucheng$ gem sources -l *** CURRENT SOURCES *** https://rubygems.org/


  - 移除 `ruby 源`
複製程式碼

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

>```
移除結果:
muxuguixiandeMacBook-Pro:local jijiucheng$ gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
複製程式碼
  • 替換新增國內映象源 ruby-china 源,因為上面已經提到國內映象源 taobao 源 已經停止維護了,所以此處替換的是 ruby-china 源,且儘量確保只有一個 ruby-china 源
$ gem sources --add https://gems.ruby-china.org
複製程式碼
複製程式碼

替換結果: muxuguixiandeMacBook-Pro:local jijiucheng$ gem sources --add https://gems.ruby-china.org https://gems.ruby-china.org added to sources

複製程式碼

再次檢查此時的 ruby 源:( 已經變成了 ruby-china 源 ) muxuguixiandeMacBook-Pro:local jijiucheng$ gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.org


- ### 3、安裝 CocoaPods
  - 安裝 CocoaPods( `sudo 表示管理員執行指令` )( `此處需要輸入一次密碼` )
複製程式碼

$ sudo gem install cocoapods

複製程式碼

注意點:<------------------------------> 此處有個注意點 由於 OS X 系統的不同,此處的指令也是有些變化: OS X 10.11之前系統的安裝 CocoaPods 指令: $ sudo gem install cocoapods OS X 10.11以後系統的安裝 CocoaPods 指令: $ sudo gem install -n /usr/local/bin cocoa pods

>```
安裝結果:(正常情況列印沒有這麼多,此處是因為解決報錯時,同時列印了這麼多)
muxuguixiandeMacBook-Pro:local jijiucheng$ sudo gem install cocoa pods
Password:   <----------------------------------->  // 此處需要輸入一次密碼 
Fetching: ffi-1.9.14.gem (100%)
Building native extensions.  This could take a while...
Successfully installed ffi-1.9.14
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
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: concurrent-ruby-1.0.2.gem (100%)
Successfully installed concurrent-ruby-1.0.2
Fetching: activesupport-5.0.0.1.gem (100%)
Successfully installed activesupport-5.0.0.1
Fetching: cocoa-0.1.6.gem (100%)
Successfully installed cocoa-0.1.6
Parsing documentation for ffi-1.9.14
Installing ri documentation for ffi-1.9.14
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for i18n-0.7.0
Installing ri documentation for i18n-0.7.0
Parsing documentation for concurrent-ruby-1.0.2
Installing ri documentation for concurrent-ruby-1.0.2
Parsing documentation for activesupport-5.0.0.1
Installing ri documentation for activesupport-5.0.0.1
Parsing documentation for cocoa-0.1.6
Installing ri documentation for cocoa-0.1.6
Done installing documentation for ffi, thread_safe, tzinfo, i18n, concurrent-ruby, activesupport, cocoa after 34 seconds
Fetching: pods-0.0.1.gem (100%)
Successfully installed pods-0.0.1
Parsing documentation for pods-0.0.1
Installing ri documentation for pods-0.0.1
Done installing documentation for pods after 0 seconds
8 gems installed
<------------------ 此處有 gems installed 標誌著安裝 CocoaPods 成功 ------------------>
複製程式碼

安裝 CocoaPods .png

  • 正常情況下此處會出現很大的坑,經常會出現各種報錯問題,大多數是為 ruby 環境過低沒有更新升級,或者是牽扯到 rvm 管理器環境的問題,在後面各種報錯問題的解決方案的中會有提到。

  • 4、配置 CocoaPods 環境

    • 說明 :此處為了做測試,在 MAC 桌面 Desktop 建立了一個工程 CocoaPodsTestDemo

    • 第一步cd 到目錄資料夾,回車 enter快速方式:直接將資料夾拖入到終端 Terminal )。

$ cd /Users/jijiucheng/Desktop/CocoaPodsTestDemo 
複製程式碼
複製程式碼

輸入結果:((^_^)此時沒有任何結果 ) muxuguixiandeMacBook-Pro:~ jijiucheng$ cd /Users/jijiucheng/Desktop/CocoaPodsTestDemo


 - **第二步(建議)**:如果不知道第三方庫版本的情況下,建議先查詢一下當前所需第三方庫的最新版本,可以通過輸入指令的方式完成。並且查詢完成後輸入 `wq` 返回之前終端 `Terminal`頁面。
複製程式碼

$ pod search 'AFNetworking'

>```
查詢結果:(因為會查詢輸出所有與 'AFNetworking' 相關的第三方庫,此處只輸出部分,其中下面的“橫線”代替實際列印的一行空格)
muxuguixiandeMacBook-Pro:~ jijiucheng$ cd /Users/jijiucheng/Desktop/CocoaPodsTestDemo 
muxuguixiandeMacBook-Pro:CocoaPodsTestDemo jijiucheng$ pod search 'AFNetworking'
--------------------------(此處是輸出結果)--------------------------
-> AFNetworking (3.1.0)
   A delightful iOS and OS X networking framework.
   pod 'AFNetworking', '~> 3.1.0'
   - Homepage: https://github.com/AFNetworking/AFNetworking
   - Source:   https://github.com/AFNetworking/AFNetworking.git
   - Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,
   3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,
   2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,
   2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,
   1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,
   1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
   - Subspecs:
     - AFNetworking/Serialization (3.1.0)
     - AFNetworking/Security (3.1.0)
     - AFNetworking/Reachability (3.1.0)
     - AFNetworking/NSURLSession (3.1.0)
     - AFNetworking/UIKit (3.1.0)
......(後面還有好多與 'AFNetworking' 相關的第三方庫,此處不一一列舉)
複製程式碼

搜尋 'AFNetworking' 列印結果.png

  • 第三步:建立 Podfile 配置檔案
$ vim Podfile
複製程式碼
複製程式碼

回車跳轉介面(如下):

![指令 vim Podfile 後跳轉介面 .png](http://upload-images.jianshu.io/upload_images/711060-a67f673c2e5bab9f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
 - ```
① 鍵盤輸入 i ,進入 Podfile 配置檔案的編輯模式,底部會變成 :
-- INSERT --
複製程式碼
複製程式碼

Podfile 配置檔案編輯模式(如下):

![Podfile 配置檔案編輯模式 .png](http://upload-images.jianshu.io/upload_images/711060-d812ea5319337128.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
 - ```
② 通過固定語句編輯進行 Podfile 檔案的配置:
複製程式碼
複製程式碼

Podfile 配置檔案固定語句(如下): ```說明:可能有些人看到的固定語句不一樣,但是大同小異,基本上都能實現最終效果。` --->

Uncomment this line to define a global platform for your project

platform :ios, '8.0' target 'CocoaPodsTestDemo' do   # Uncomment this line if you're using Swift or would like to use dynamic frameworks   # Pods for CocoaPodsTestDemo      pod 'AFNetworking', '~>3.1.0'      pod 'SDWebImage'      pod 'MBProgressHUD'      pod 'FMDB'      pod 'Masonry'      pod 'MJExtension'      pod 'MJRefresh'

use_frameworks!

pod 'ReactiveCocoa'

end

![Podfile 配置檔案固定語句 .png](http://upload-images.jianshu.io/upload_images/711060-edb4e3eb4047a035.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
 - ```
③ 當固定語句輸入完畢之後,按一次 `Esc` 按鍵退出編輯模式,底部就沒有 `-- INSERT --` 標識了;
再按一次 `shift + :` ( 英文輸入法狀態下 )組合,底部就會出現一個 `冒號 :` ;
最後再輸入 `wq` 回車,返回到配置 Podfile 檔案之前的介面;
此時 Podfile 檔案就配置好了;
此時可以在 `CocoaPodsTestDemo` 資料夾下發現多了一個 `Podfile` 檔案。
複製程式碼
複製程式碼

Podfile 輸入完畢之後(如下):

![Podfile 輸入完畢之後 .png](http://upload-images.jianshu.io/upload_images/711060-718d2be704c64c8f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![配置檔案完成後新增 Podfile 檔案 .png](http://upload-images.jianshu.io/upload_images/711060-3ba0fd1a2c88bc43.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

  - **第四步**:下載第三方庫檔案到專案工程中
複製程式碼

$ pod install

>```
下載輸出(如下):
muxuguixiandeMacBook-Pro:CocoaPodsTestDemo jijiucheng$ pod install
Analyzing dependencies
Downloading dependencies
Installing AFNetworking (3.1.0)
Installing FMDB (2.6.2)
Installing MBProgressHUD (1.0.0)
Installing MJExtension (3.0.13)
Installing MJRefresh (3.1.12)
Installing Masonry (1.0.2)
Installing SDWebImage (3.8.2)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `CocoaPodsTestDemo.xcworkspace` for this project from now on.
Pod installation complete! There are 7 dependencies from the Podfile and 7 total pods
installed.
複製程式碼

下載第三方庫檔案到專案工程中 .png
安裝 CocoaPods 成功後專案檔案變化 .png

  • ** 第五步 **:此後開啟專案工程只需要點選開啟 CocoaPodsTestDemo.xcworkspace 檔案即可
複製程式碼

開啟工程檔案目錄變化(如下): 所有的第三方庫檔案都在 /CocoaPodsTestDemo/Pods/Pods 資料夾目錄下

![開啟工程檔案目錄變化 .png](http://upload-images.jianshu.io/upload_images/711060-b4042e8dde397cbd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)



# 三、CocoaPods 安裝過程中報錯問題解決
<p>
- ##### 說明:此部分所列舉的問題均是在執行相關指令時出現的報錯
<p>
- ### 1、Rvm 環境搭建
   - **報錯一:**
**① Error running 'requirements_osx_brew_update_system ruby-2.3.0', showing last 15 lines of /Users/jijiucheng/.rvm/log/1475769205_ruby-2.3.0/update_system.log
② curl: (35) Server aborted the SSL handshake**
<p>
> *① 報錯指令:*
複製程式碼

$ rvm install 2.3.0

*② 報錯資訊:*
複製程式碼

Error running 'requirements_osx_brew_update_system ruby-2.3.0', showing last 15 lines of /Users/jijiucheng/.rvm/log/1475769205_ruby-2.3.0/update_system.log ...... ...... Requirements installation failed with status: 1.

複製程式碼

curl: (35) Server aborted the SSL handshake

![報錯資訊 1.png](http://upload-images.jianshu.io/upload_images/711060-10e836d4fc9eecfa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![報錯資訊 2.png](http://upload-images.jianshu.io/upload_images/711060-53fd622f1b0feb16.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*③ 報錯原因:*
`網路問題,因為需要翻牆,所以網路不穩定;建議選擇 VPN,保證線路的穩定性。`
<p>
*④ 解決方案( 指令一行一行輸入 ):*
複製程式碼

$ cd /usr/local

複製程式碼

$ git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

複製程式碼

$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bashrc

![解決方案 .png](http://upload-images.jianshu.io/upload_images/711060-e53b3d21011be5fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*⑤ 方案連結:*
[方案解決連結 -- https://segmentfault.com/q/1010000004276750](https://segmentfault.com/q/1010000004276750)

   - **報錯二:**
**① Error running '__rvm_make -j 1', 
showing last 15 lines of /Users/jijiucheng/.rvm/log/1475769349_ruby-2.3.0/make.log
**
> *① 報錯指令:*
複製程式碼

$ rvm install 2.3.0

*② 報錯資訊:*
複製程式碼

Error running '__rvm_make -j 1', showing last 15 lines of /Users/jijiucheng/.rvm/log/1475769349_ruby-2.3.0/make.log ...... ...... There has been an error while running make. Halting the installation.

![報錯資訊 .png](http://upload-images.jianshu.io/upload_images/711060-2b536f8210eadeb9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*③ 報錯原因:*
`缺少 Xcode 工具,xcode command line`
<p>
*④ 解決方案:*
複製程式碼

$ xcode-select --install

![解決方案 .png](http://upload-images.jianshu.io/upload_images/711060-5b7b4c3da30fd277.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*⑤ 方案連結:*
[方案解決連結 1 - http://stackoverflow.com/questions/35228481/error-running-rvm-make-install](http://stackoverflow.com/questions/35228481/error-running-rvm-make-install)
[方案解決連結 2 - http://www.th7.cn/Program/Ruby/201609/966343.shtml](http://www.th7.cn/Program/Ruby/201609/966343.shtml)

   - **報錯三:**
**① Gemset '' does not exist, 'rvm ruby-2.3.0 do rvm gemset create ' first, or append '--create'.
**
> *① 報錯指令:*
複製程式碼

$ rvm install 2.3.0

*② 報錯資訊:*
複製程式碼

muxuguixiandeMacBook-Pro:local jijiucheng$ rvm install 2.3.0 Already installed ruby-2.3.0. To reinstall use: .     rvm reinstall ruby-2.3.0 . Gemset '' does not exist, 'rvm ruby-2.3.0 do rvm gemset create ' first, or append '--create'.

![報錯資訊 .png](http://upload-images.jianshu.io/upload_images/711060-85ed75cf008139b9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*③ 報錯原因:*
`指令不對,已經存在 ruby-2.3.0 的檔案殘留,需要重新安裝;`
<p>
*④ 解決方案:*
複製程式碼

$ rvm reinstall ruby-2.3.0

![解決方案 .png](http://upload-images.jianshu.io/upload_images/711060-cf2af9da6f2bb499.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

- ### 2、Ruby 環境搭建
   - **報錯一:**

- ### 3、CocoaPods 安裝
- ### 4、CocoaPods 配置使用
   - **報錯一:**
**① Setting up CocoaPods master repo**
**② [!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master`. You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.**
> *① 報錯指令:*
複製程式碼

$ pod install

*② 報錯資訊:*
複製程式碼

muxuguixiandeMacBook-Pro:NFCustomer jijiucheng$ pod install Setting up CocoaPods master repo [!] Unable to add a source with url https://github.com/CocoaPods/Specs.git named master. You can try adding it manually in ~/.cocoapods/repos or via pod repo add.

![報錯資訊 .png](http://upload-images.jianshu.io/upload_images/711060-9775d53e12cb8c56.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*③ 報錯原因:*
`由於安裝了多個Xcode導致路徑變了,需要變換路徑:
sudo xcode-select -switch /Applications/Xcode.app 
sudo xcode-select -switch /Applications/Xcode\ 2.app `
<p>
*④ 解決方案:*
複製程式碼

$ sudo xcode-select -switch /Applications/Xcode.app

![解決方案 .png](http://upload-images.jianshu.io/upload_images/711060-ed32f3dec2959b43.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
*⑤ 資料補充:*
`出現 Setting up CocoaPods master repo,說明 Cocoapods 在將它的資訊下載到  ~/.cocoapods 裡;
新建立終端視窗,輸入 cd ~/.cocoapods ,回車,輸入 du -sh *  命令來檢視檔案大小,
每隔幾分鐘檢視一次,這個目錄最終大小是100多M( 本人這裡大概 800M + ),就是完成了。`
<p>
*⑥ 方案連結:*
[方案解決連結 1 - ios開發怎樣解除安裝已經安裝的cocoapod](http://zhidao.baidu.com/link?url=WZj_AtGSTkdb0J3G09EdHxqNaD6eM6Uf5u-Qp6-SrFbDBUzA5Bhka9qQ_uHQe67Pn51nWw3wrulL2vy-nfal8KpLqMN_5-ahsYHY6G_8eOa)
[方案解決連結 2 - CocoaPods安裝和使用及問題:Setting up CocoaPods master repo](http://blog.csdn.net/zhangjunjian127/article/details/47954981)


# 四、資料補充
<p>
- #### 1、指令補全
  - **① Rvm 指令庫**
<p>
複製程式碼

$ ruby -v # 檢視ruby 版本 $ rvm list known # 列出已知的 ruby 版本 $ rvm install 2.3.0 # 選擇指定 ruby 版本進行更新 $ rvm get stable # 更新 rvm $ rvm use 2.2.2 # 切換到指定 ruby 版本 $ rvm use 2.2.2 --default # 設定指定 ruby 版本為預設版本
$ rvm list # 查詢已安裝的 ruby 版本 $ rvm remove 1.9.2 # 解除安裝移除 指定 ruby 版本

複製程式碼

$ curl -L https://get.rvm.io | bash -s stable # 安裝 rvm 環境 $ curl -sSL https://get.rvm.io | bash -s stable --ruby # 預設安裝 rvm 最新版本 $ curl -sSL https://get.rvm.io | bash -s stable --ruby=2.3.0 # 安裝 rvm 指定版本 $ source ~/.rvm/scripts/rvm # 載入 rvm

 - **②  gem 指令庫**
<p>
複製程式碼

$ gem -v # 檢視 gem 版本 $ gem source # 檢視 gem 配置源 $ gem source -l # 檢視 gem 配置源目錄 $ gem sources -a url # 新增 gem 配置源(url 需換成網址) $ gem sources --add url # 新增 gem 配置源(url 需換成網址) $ gem sources -r url # 刪除 gem 配置源(url 需換成網址) $ gem sources --remove url # 刪除 gem 配置源(url 需換成網址) $ gem update # 更新 所有包 $ gem update --system # 更新 Ruby Gems 軟體 $ $ gem install rake # 安裝 rake,從本地或遠端伺服器 $ gem install rake --remote # 安裝 rake,從遠端伺服器 $ gem install watir -v 1.6.2 # 安裝 指定版本的 watir $ gem install watir --version 1.6.2 # 安裝 指定版本的 watir $ gem uninstall rake # 解除安裝 rake 包 $ gem list d # 列出 本地以 d 打頭的包 $ gem query -n ''[0-9]'' --local # 查詢 本地含有數字的包 $ gem search log --both # 查詢 從本地和遠端伺服器上查詢含有 log 字串的包 $ gem search log --remoter # 查詢 只從遠端伺服器上查詢含有 log 字串的包 $ gem search -r log # 查詢 只從遠端伺服器上查詢含有log字串的包 $ $ gem help # 提醒式的幫助 $ gem help install # 列出 install 命令 幫助 $ gem help examples # 列出 gem 命令使用一些例子 $ gem build rake.gemspec # 把 rake.gemspec 編譯成 rake.gem $ gem check -v pkg/rake-0.4.0.gem # 檢測 rake 是否有效 $ gem cleanup # 清除 所有包舊版本,保留最新版本 $ gem contents rake # 顯示 rake 包中所包含的檔案 $ gem dependency rails -v 0.10.1 # 列出 與 rails 相互依賴的包 $ gem environment # 檢視 gem 的環境 $ $ sudo gem -v # 檢視 gem 版本(以管理員許可權) $ sudo gem install cocoa pods # 安裝 CocoaPods(以管理員許可權) $ sudo gem install cocoapods # 安裝 CocoaPods(以管理員許可權) $ sudo gem install cocoapods --pre # 安裝 CocoaPods 至預覽版(以管理員許可權) $ sudo gem install cocoapods -v 0.39.0 # 安裝 CocoaPods 指定版本(以管理員許可權) $ sudo gem update cocoapods # 更新 CocoaPods 至最新版(以管理員許可權) $ sudo gem update cocoapods --pre # 更新 CocoaPods 至預覽版(以管理員許可權) $ sudo gem uninstall cocoapods -v 0.39.0 # 移除 CocoaPods 指定版本(以管理員許可權)

 - **③  pod 指令庫**
<p>
複製程式碼

$ pod setup # CocoaPods 將資訊下載到~/.cocoapods/repos 目錄下。如果安裝 CocoaPods 時不執行此命令,在初次執行 pod intall 命令時,系統也會自動執行該指令 $ pod --version # 檢查 CocoaPods 是否安裝成功及其版本號 $ pod install # 安裝 CocoaPods 的配置檔案 Podfile



# 五、引用資料
<p>
- ##### 說明:此處是列舉了我安裝CocoaPods 和寫這篇文章時查詢引用的文章,如有涉及到版權問題,請聯絡,我會刪除的。
<p>
- **01** - [Rvm、Ruby及Cocoapods安裝](http://www.jianshu.com/p/934849a5232a)
- **02** - [RVM 和 Ruby的安裝](http://www.jianshu.com/p/7fedee946f40)
- **03** - [iOS的庫依賴管理工具CocoaPods](http://www.jianshu.com/p/0cea9006c0cb)
- **04** - [CocoaPods的安裝以及遇到的坑](http://www.cocoachina.com/ios/20160922/17622.html)
- **05** - [ios開發怎樣解除安裝已經安裝的cocoapod](http://zhidao.baidu.com/link?url=WZj_AtGSTkdb0J3G09EdHxqNaD6eM6Uf5u-Qp6-SrFbDBUzA5Bhka9qQ_uHQe67Pn51nWw3wrulL2vy-nfal8KpLqMN_5-ahsYHY6G_8eOa)
- **06** - [配置CocoaPods前 - 本地安裝好Ruby環境](http://www.cnblogs.com/cwllong/p/5072882.html)
- **07** - [iOS 學習筆記二【cocopods安裝使用和安裝過程中遇到的問題及解決辦法】【20160725更新】](http://www.cnblogs.com/boai/p/4977976.html)
- **08** - [ruby學習及編譯ruby缺少openssl問題解決](http://www.cnblogs.com/netbuddy/p/3501147.html)
<p>
- **01** - [解決升級EI Capiton CocoaPods "pod: command not found"](http://www.jianshu.com/p/6ff1903c3f11)
- **02** - [curl: (35) Server aborted the SSL handshake](https://segmentfault.com/q/1010000004276750)
- **03** - [第一種 - Error running '__rvm_make -j 1'](http://stackoverflow.com/questions/35228481/error-running-rvm-make-install)
- **04** - [第二種 - Error running '__rvm_make -j 1'](http://www.th7.cn/Program/Ruby/201609/966343.shtml)
- **05** - [[!] Unable to add a source with url "xxxxxxxxxxxxx"](http://zhidao.baidu.com/link?url=WZj_AtGSTkdb0J3G09EdHxqNaD6eM6Uf5u-Qp6-SrFbDBUzA5Bhka9qQ_uHQe67Pn51nWw3wrulL2vy-nfal8KpLqMN_5-ahsYHY6G_8eOa)
- **06** - [Error running 'requirements_osx_brew_update_system ruby-2.0.0-p643'](http://blog.csdn.net/luohancc/article/details/46897247)
- **07** - [關於安裝cocoapods遇到的一些坑(ERROR: Error installing cocoapods: activesupport requires Ruby version >= 2.2)](http://blog.csdn.net/fairytale_1/article/details/51850734)
- **08** - [Homebrew install: Failed during: git fetch origin master:refs/remotes/origin/master -n --depth=1](http://stackoverflow.com/questions/39836190/homebrew-install-failed-during-git-fetch-origin-masterrefs-remotes-origin-mas)
- **09** - [Pod /usr/bin/git clone https://github.com/CocoaPods/Specs.git master](http://www.jianshu.com/p/90ca71b3b94a)


<p>
# 六、後續更新
<p>
- ### 2016.12.15  問題更新
 - **安裝 CocoaPods 步驟指令問題**
>① 最初寫的:
複製程式碼

由於 OS X 系統的不同,此處的指令也是有些變化: OS X 10.11之前系統的安裝 CocoaPods 指令: $ sudo gem install cocoapods OS X 10.11以後系統的安裝 CocoaPods 指令: $ sudo gem install -n /usr/local/bin cocoa pods

② 更改原因:
 *因為有朋友說在 `mac OS 10.11` 和 `mac OS 10.12` 環境中所用的指令不一樣,當時寫這篇文章的時候環境是 `mac OS 10.11` ,但是並沒有做 `mac OS 10.12` 的環境,今天又做了一下測試,現在的環境是 `mac OS 10.12.1`。*
![測試環境 mac OS 10.12.1.png](http://upload-images.jianshu.io/upload_images/711060-2a771a61d55e2848.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
③ 測試結果:
`----> 指令:
----> $ sudo gem install cocoa pods 
----> 不需要密碼 `
![指令:$ sudo gem install cocoa pods 測試結果.png](http://upload-images.jianshu.io/upload_images/711060-77bee925cb289a85.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
`----> 指令:
----> $ sudo gem install cocoapods 
----> 需要密碼 `
![指令:$ sudo gem install cocoapods 測試結果.png](http://upload-images.jianshu.io/upload_images/711060-ba1476d9a9075c4c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
`----> 指令:
----> $ sudo gem install -n /usr/local/bin cocoa pods 
----> 需要密碼 `
![指令:$ sudo gem install -n /usr/local/bin cocoa pods 測試結果.png](http://upload-images.jianshu.io/upload_images/711060-c9e35cae327c961e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
④ 測試結論:
`三種結果都能安裝 Cocoapods 成功,只不過安裝更新的內容略有不同。
推薦使用:指令:$ sudo gem install cocoapods`




----
<p>
### 報錯資訊板塊尚未寫完,後面有時間會繼續完善!!!
<p>
### 如果有錯誤的資訊,希望大家可以指出,進而及時修改,相互學習!!!
<p>
### 如有轉載的,希望可以註明出處!!!
<p>

----
複製程式碼

相關文章