1 .安装 CocoaPods 首先需要安装好Ruby 环境,Mac 中本身就自带了Ruby 环境。
所以你可以查看你当起的Ruby的版本 是否需要升级才能安装CocoaPods。
当前的版本 命令: $ ruby -v
输出结果:
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
安装 CocoaPods 命令:
$ sudo gem install cocoapods
输出结果:ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
命令:
gem sources -l(查看当前)
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l(再次查看当前
*** CURRENT SOURCES ***
: https://ruby.taobao.org/)
然后继续试下上面的 安装CocoaPods 命令:$ sudo gem install cocoapods
发现又报错了:
ERROR: Error installing cocoapods:
activesupport requires Ruby version >= 2.2.2. 版本太低
升级命令:
$ sudo gem update --system
成功提示:RubyGems system software updated
继续安装 CocoaPods 命令:
$ sudo gem install cocoapods
还是报错说版本 requires Ruby version >= 2.2.2. ,
输入ruby -v 命令确实还是 ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15],
输入更新的命令 sudo gem update --system ,确提示: Latest version currently installed. Aborting. ???? ....接着
2. 安装RVM 通过Rvm 升级 ruby 版本 , 命令: curl -sSL https://get.rvm.io | bash -s stable 完成以后 接着执行:
source ~/.bashrc
source ~/.bash_profile
rvm -v
输出:
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
输入命令: ruby -v
输出:ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
3.使用 RVM 升级ruby
输入命令:rvm list known
输出 :
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.8]
[ruby-]2.2[.4]
[ruby-]2.3[.0]
[ruby-]2.2-head
ruby-head
# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2
# JRuby
jruby-1.6[.8]
jruby-1.7[.23]
jruby[-9.0.5.0]
jruby-head
# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx[-2.5.8]
rbx-head
# Opal
opal
# Minimalistic ruby implementation - ISO 30170:2012
mruby[-head]
# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]
# GoRuby
goruby
# Topaz
topaz
# MagLev
maglev[-head]
maglev-1.0.0
# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head
# IronRuby
ironruby[-1.1.3]
ironruby-head
选择一个版本 安装
命令: rvm install 2.3
.....
ruby-2.3.0 - #downloading ruby-2.3.0, 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 13.5M 100 13.5M 0 0 294k 0 0:00:47 0:00:47 --:--:-- 535k
ruby-2.3.0 - #extracting ruby-2.3.0 to /Users/davis/.rvm/src/ruby-2.3.0....
ruby-2.3.0 - #configuring......................................................|
ruby-2.3.0 - #post-configuration.
ruby-2.3.0 - #compiling........................................................|
ruby-2.3.0 - #installing.........
ruby-2.3.0 - #making binaries executable..
Installed rubygems 2.5.1 is newer than 2.4.8 provided with installed ruby, skipping installation, use --force to force installation.
ruby-2.3.0 - #gemset created /Users/davis/.rvm/gems/ruby-2.3.0@global
ruby-2.3.0 - #importing gemset /Users/davis/.rvm/gemsets/global.gems...........|
ruby-2.3.0 - #generating global wrappers........
ruby-2.3.0 - #gemset created /Users/davis/.rvm/gems/ruby-2.3.0
ruby-2.3.0 - #importing gemsetfile /Users/davis/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.3.0 - #generating default wrappers........
ruby-2.3.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.3.0 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
终于搞定,继续还是检查下 ruby 的版本:ruby -v
终于升级了:ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
再次安装cocoapods
命令 : sudo gem install cocoapods
就安装成功了。