已经不是第一次安装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
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
输入命令: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 update
curl
错误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
$ 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文件 , 把 要安装的东西复制上
先安装xcode command line 便可解决
$ xcode-select --install