安装失败大部分原因是ruby版本过低:
命令行中显示:
$ sudo gem install -n /usr/local/bin cocoapods
ERROR: Error installing cocoapods:
activesupport requires Ruby version >= 2.2.2.
查看ruby版本后发现版本过低
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
安装过程如下:
1升级ruby
傻瓜式的步骤:
1、安装 RVM
RVM:Ruby Version Manager,Ruby版本管理器,包括Ruby的版本管理和Gem库管理(gemset)
等待一段时间后就可以成功安装好 RVM。(等着就好了,不到10秒吧.)
测试是否安装正常,(以上两个命令行敲了不会显示什么,但是需要敲。
- rvm -v
显示版本,会出现下边的样子(当然版本会由于时间的关系显示的不一样,下边的除了版本数不一定一样,其他的都是套路)
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
2、用RVM升级Ruby
主要是第五行,看一下当前的版本有哪些?然后第七行安装个版本高点的(老板,来个2.2的)~
当然如果你看到这篇文章的时候版本可能会更高,你就别选2.2的了,版本能多高就多高吧少年.
控制台打印出:
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.11/x86_64/ruby-2.2.4.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
About to install Homebrew, press `Enter` for default installation in `/usr/local`,
type new path if you wish custom Homebrew installation (the path needs to be writable for user)
:
(1)直接按回车(安装Homebrew):
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
==> The following directories will be made group writable:
.......
Homebrew安装完后:
==> Homebrew has enabled anonymous aggregate user behaviour analytics
Read the analytics documentation (and how to opt-out) here:
https://git.io/brew-analytics
Installing requirements for osx.
Updating system.....
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl.....\
(2)直接按回车,开始下载按钮ruby2.2.4:
...
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/apple/.rvm/rubies/ruby-2.2.4, this may take a while depending on your cpu(s)...
ruby-2.2.4 - #downloading ruby-2.2.4, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.7M 100 12.7M 0 0 229k 0 0:00:56 0:00:56 --:--:-- 242k
ruby-2.2.4 - #extracting ruby-2.2.4 to /Users/apple/.rvm/src/ruby-2.2.4....
ruby-2.2.4 - #applying patch /Users/apple/.rvm/patches/ruby/2.2.4/fix_installing_bundled_gems.patch.
大概10s后,ruby2.2.4安装完成。
然后查看版本:
命令:ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]
(3)进一步升级ruby:
命令:sudo gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.6.6.gem (100%)
Successfully installed rubygems-update-2.6.6
Parsing documentation for rubygems-update-2.6.6
Installing ri documentation for rubygems-update-2.6.6
Installing darkfish documentation for rubygems-update-2.6.6
Done installing documentation for rubygems-update after 26 seconds
Parsing documentation for rubygems-update-2.6.6
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 2.6.6
RubyGems 2.6.6 installed
Parsing documentation for rubygems-2.6.6
Installing ri documentation for rubygems-2.6.6
=== 2.6.6 / 2016-06-22
升级到的2.6.6版本
3.切换数据源:
命令:
gem source --remove https://rubygems.org/
gem source -a https://ruby.taobao.org/
gem source -l
4.安装cocoapods:
命令:sudo gem install cocoapods
等待安装完成吧。。。。