多個Cocoapods如何共存并自由切換?

Cocoapods多版本共存并自由切換?

親,我的簡書已不再維護和更新了,所有文章都遷移到了我的個人博客:https://mikefighting.github.io/,歡迎交流。

Cocoapods是IOS中的第三方框架管理工具,一臺電腦為什么要安裝多個版本的Cocoapods呢?在公司里可能存在不同的IOS開發團隊分別對不同的業務線進行開發,各個團隊之間所用的Cocoapod版本不同,這時你被外派到另外一個團隊做開發。

Rubyems:簡稱gems是一個用于對rails組建近些年個打包的ruby打包系統,它提供了一個分發ruby程序喝庫的標準格式,還提供了一個管理程序包的工具。Rubyems的功能類似于linux下的apt-get,是個包管理器,可以從遠程下載所需的包。

gem:你可以這樣理解,gem是一系列文件和包的總稱,是一些rails項目依賴的軟件或者環境,或者是依賴的關系庫,當你的項目中缺少的時候,你可以用gem install 來進行安裝,這種安裝是通過RubyGems這個包管理工具來安裝的,當然你也可以通過bundleer來安裝。

RVM:Ruby Version Manager,ruby版本管理工具,利用它可以很方便的安裝多個版本的Ruby。

實現的原理

通過RVM來安裝多個版本的ruby,再根據不同版本的ruby來安裝相應版本的cocoapods,最后使用rvm use命令切換不同的ruby環境來使用不同版本的cocoapods.

一、常用的幾個指令:

  • ruby -v查看rugy的版本()
  • rvm -v (查看rvm的版本)
  • gem sources -l(查看gem shources)
  • rvm list(查看已安裝的所有版本:ruby)
  • rvm use rubyVersion(使用某個版本的ruby),例如:rvm use ruby-2.3.3
  • rvm install rubyVersion(安裝某個版本的ruby),例如:rvm install 2.3.3
  • rvm use rubyVersion --default(將某個版本的ruby設置為默認版本),例如rvm use 1.9.3 --default
  • rvm remove rubyVersion(刪除某個版本的ruby),例如:rvm remove 1.9.3
  • rvm list known查看所有可用的ruby版本
  • sudo gem install cocoapods -v <Version> -n /usr/local/bin安裝cocoapod
  • gem list查看當前gem下的所有安裝包

實現步驟:

步驟一、 執行rvm -v,如果發現沒有rvm則執行curl -L get.rvm.io | bash -s stable && source ~/.rvm/scripts/rvm安裝rvm.
步驟二、 執行rvm list known查看所有可用的ruby版本,然后執行rvm install someVersion來執相應版本的ruby; 或者從ruby官網上下載不同版本Ruby時,一定要下載osx操作系統的,否則在執行rvm mount ~/Downloads/ruby-2.3.3.tar.bz2時,將會出現Libraries missing for ruby-2.3.3: xcrun. Refer to your system manual for installing libraries,下載完之后到響應的目錄下執行rvm mount ruby-2.2.3.tar.bz2就可以安裝對應的ruby。
步驟三、重復執行步驟二,安裝不同版本的ruby,

各種錯誤及處理方式:

  1. 執行完:rvm use ruby-2.3.3sudo gem install cocoapods之后出現:/Users/a58/.rvm/rubies/ruby-2.3.3/bin/ruby: /Users/a58/.rvm/rubies/ruby-2.3.3/bin/ruby: cannot execute binary file這種錯誤。
  2. 執行完rvm use ruby-2.2.3,出現Gemset '' does not exist, 'rvm ruby-2.2.3 do rvm gemset create ' first, or append '--create'.這種錯誤是由于沒有設置default,在執行rvm list的時候會出現如下# Default ruby not set. Try 'rvm alias create default <ruby>'.
    這樣的提示。使用rvm --create ruby-2.1.9 之后這種提示消失。逐個將其他版本的ruby也使用rvm --create rubyVersion這個指令,然后就可以切換至不同版本的ruby了。
  3. 在執行sudo gem install cocoapods來安裝cocoapods 的時候,ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why: Unable to download data from https://ruby.taobao.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://ruby.taobao.org/specs.4.8.gz),這是因為淘寶鏡像最近出問題了,使用gem sources -a http://rubygems-china.oss.aliyuncs.com再安裝一個鏡像,然后可以執行sudo gem install cocoapods了,但是在執行pod -v,pod search AFNetworking,pod setup時卻發現:/Users/a58/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:315:in 'to_specs': Could not find 'cocoapods' (>= 0) among 6 total gem(s) (Gem::LoadError)
  4. 在執行rvm install 2.1.0時報錯xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist, use 'xcode-select --switch path/to/Xcode.app' to specify the Xcode that you wish to use for command line developer tools (or see 'man xcode-select')這是因為rvm尋找的路徑是/Applications/Xcode.app/Contents/Developer,而我的Xcode被我修改成了Xcode8.0,找不到路徑了,所以把Xcode的名字改過來就好了。
  5. Error running 'requirements_osx_brew_update_system ruby-2.1.0', showing last 15 lines of /Users/a58/.rvm/log/1487732911_ruby-2.1.0/update_system.log,這個時候需要更新Homebrew,執行brew update來更新Homebrew,這時卻發現Error: /usr/local must be writable!,然后點擊Command + Shift + G,然后輸入/usr這個時候就看到usr目錄,找到下面的local文件夾,右擊"Get Info",將最下面的權限中的everyone改為可讀寫的,這時就可以執行brew update指令了。執行完之后再執行rvm install ruby 2.2.2,就可看到如下圖所示,就說明ruby安裝成功了: 執行sudo gem install cocoapods這個指令就可以成安裝cocoapods了,接著執行pod --version,就可以查看當前的pod版本號了:/Users/a58/.rvm/gems/ruby-2.2.2@global/gems/cocoapods-1.2.0/lib/cocoapods/executable.rb:89: warning: Insecure world writable dir /usr/local in PATH, mode 040777 1.2.0;
  6. 在執行完brew update之后再執行有關pod的指令還是會報錯/Users/a58/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/dependency.rb:315:in 'to_specs': Could not find 'cocoapods' (>= 0) among 6 total gem(s) (Gem::LoadError)這樣的錯誤。然后把現有的cocoapod卸載,執行sudo gem uninstall cocoapods,卸載完之后執行sudo gem install cocoapods -v 1.2.0 -n /usr/local/bin,這時依然會出現這個錯誤
  7. 在使用2.0.0版本的ruby安裝pod的時候出現如下錯誤ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20) ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store ERROR: SSL verification error at depth 2: self signed certificate in certificate chain (19) ERROR: Root certificate is not trusted (/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA) ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod
  8. 在osx是10.11.6的時候,gem update --system會出錯,ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/update_rubygems,這時候需要到rubyGem的官網現在最新的zip文件,解壓進入到rubygems-2.6.10文件中,然后執行ruby setup.rb就可以安裝gem了。
  9. 刪除某個版本的ruby的時候,出現ruby-2.2.3 [ missing bin/ruby ],這時前往/Users/用戶名/.rvm/rubies/ruby-2.2.3,然后刪除對應的ruby-2.2.3即可。
  10. rvm instlall 2.2.3 報錯Empty path passed to certificates update, functions stack: requirements_osx_update_openssl_cert_run rvm_requiremnts_fail_or_run_action __rvm_osx_ssl_certs_ensure_for_ruby __rvm_osx_ssl_certs_ensure_for_ruby_except_jruby external_import_setup external_import main,這時執行rvm reinstall 2.2.3 --disable-binary。這個時候又出現錯誤dyld: lazy symbol binding failed: Symbol not found: _clock_gettime dyld: Symbol not found: _clock_gettime,其原因在于沒有安裝Xcode的CommandLineTools工具
    執行下面的代碼:xcode-select --install即可。
  11. 安裝pod時候出現 ERROR: While executing gem ... (TypeError) no implicit conversion of nil into String執行:gem update --system
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容