已经不是第一次安装cocoapods了, 但是今天在自己的mac pro 安装cocoapods 出现了 Error installing pods:active support requires Ruby version >= 2.2.2
之前安装并没有出现个这个问题, 查了半天资料发现原来是ruby的版本太低了, 需要跟新Ruby. 然后接二连三的坑就出现了.

首先要更新Ruby , 有三种选择
1.下载ruby源代码,编译,安装
2.使用发行版自带的安装包,安装
3.使用 rvm安装

我选择了 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:

  • '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.

输入命令:

$ rvm reload
$ rvm -v
4.查看当前ruby版本 ,获取rvm 列表

$ ruby -v $ rvm list known
5.安装ruby可能出的错误 (若未出错, 请跳过进入第6步)

$ rvm install 2.3
错误1: 在安装ruby的时候, 可能会如下报错, 提示 Updating system[YourMacName] password required for ‘port -dv self update’

解决:
进行更新:

$ sudo port self update

错误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文件 , 把 要安装的东西复制上

gAaZCEfflF2nGpia.png

屏幕快照 2016-01-15 下午5.22.45.png

最后, $ pod update

你可能感兴趣的内容
iOS开发-CocoaPods实战 收藏,2472 浏览
CocoaPods的安装与使用 收藏,1864 浏览
0条评论
UT

Utkash-Bhatt

这家伙太懒了,什么都没留下
Owner