iOS- -安裝cocopods

已經不是第一次安裝cocoapods了, 可是今天在本身的mac pro 安裝cocoapods 出現了 Error installing pods:active support requires Ruby version >= 2.2.2
以前安裝並無出現個這個問題, 查了半天資料發現原來是ruby的版本過低了, 須要跟新Ruby. 而後連續不斷的坑就出現了.ios

首先要更新Ruby , 有三種選擇
1.下載ruby源代碼,編譯,安裝
2.使用發行版自帶的安裝包,安裝
3.使用 rvm安裝git

我選擇了 rvm安裝, 那勢必得先安裝 rvm

1.RVM:Ruby Version Manager,Ruby版本管理器,包括Ruby的版本管理和Gem庫管理(gems)
$ curl -L get.rvm.io | bash -s stable
2.加載文件, 測試是否安裝正常(按照提示操做)
$ source ~/.bashrc $ source ~/.bash_profile $ source ~/.profile $ rvm -v
3.若是有下面的提示, 請reload rvm
A RVM version 1.27.0 (latest) is installed yet 1.25.23 (stable) is loaded.
Please do one of the following:github

  • 'rvm reload'
  • open a new shell
  • 'echo rvm_auto_reload_flag=1 >> ~/.rvmrc' # for auto reload with msg.
  • 'echo rvm_auto_reload_flag=2 >> ~/.rvmrc' # for silent auto reload.

輸入命令:shell

$ rvm reload
$ rvm -v
4.查看當前ruby版本 ,獲取rvm 列表xcode

$ ruby -v $ rvm list known
5.安裝ruby可能出的錯誤 (若未出錯, 請跳過進入第6步)ruby

$ rvm install 2.3
錯誤1: 在安裝ruby的時候, 可能會以下報錯, 提示 Updating system[YourMacName] password required for ‘port -dv self update’bash

解決:
進行更新:服務器

$ sudo port self updatecurl

錯誤2:
或者你可能遇到以下錯誤, 緣由是須要安裝Homebrew.
Error running 'requirements_osx_port_libs_install curl-ca-bundle automake libtool libyaml libffi libksba', showing last 15 lines of /Users/acewill/.rvm/log/1468253599_ruby-2.3.0/package_install_curl-ca-bundle_automake_libtool_libyaml_libffi_libksba.log測試

解決:
參照stack overflow上的問題Installing RVM: 「Requirements installation failed with status: 1.」

須要安裝Homebrew , 經過如下命令:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

6.從新安裝ruby
安裝完成後, 從新執行安裝cocoapods的命令.

$ rvm install 2.3
7.安裝rails

$ gem install rails
8.卸載ruby方法
獲取ruby已安裝列表, 而後卸載ruby

$ rvm list $ rvm remove 2.3

配置好ruby終於能夠安裝cocoa pods了, 接下來的操做和原來是同樣的

$ gem sources -l (查看當前ruby的源)
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
2.而後從新執行安裝下載命令
$ sudo gem install cocoapods
執行pod install 命令

出現Setting up CocoaPods master repo,說明Cocoapods在將它的信息下載到 ~/.cocoapods裏;

$ pod setup
(若是執行pod setup 使用的時候又出現問題, 注意一下podfile文件裏面的格式,改爲:

platform :ios, '8.0' target '你的項目名稱' do pod 'AFNetworking', '~> 3.1.0' end

)
Terminal會停留在 Setting up CocoaPods master repo 這個狀態一段時間,是由於要進行下載安裝,並且目錄比較大,須要耐心等待一下.若是想加快速度,可以使用cocoapods的鏡像索引.
如何使用CocoaPods的鏡像索引:
全部項目的Podspec文件都託管在https://github.com/CocoaPods/Specs,第一次執行pod setup時,CocoaPods會將這些podspec索引文件更新到本地的~/.cocoapods目錄下,這個索引文件比較大,因此第一次更新時很是慢.友好人士在國內的服務器創建了Cocoapods索引庫的鏡像,因此執行索引跟新操做時候會快不少.具體操做方法以下:$ pod repo remove master
$ pod repo add master https://gitcafe.com/akuandev/Specs.git
$ pod repo update
這是使用gitcafe上的鏡像,將以上代碼中的 https://gitcafe.com/akuandev/Specs.git 替換成 https://git.oschina.net/akuandev/Specs.git 便可使用oschina上的鏡像。

cd 工程直接拽進去
pod init, 生成Podfile文件
pod search afn 搜索關鍵字 支持模糊查詢 MJre

而後找到工程裏的pod file文件 , 把 要安裝的東西複製上


 
Error running '__rvm_make -j 1',
showing last 15 lines of /Users/GDarkness/.rvm/log/1474100434_ruby-2.2.4/make.log

先安裝xcode command line 便可解決

$ xcode-select --install

相關文章
相關標籤/搜索