您的当前位置:首页正文

iOS-安装和使用 CocoaPods

来源:花图问答

2017年06月07日更新:

  • rvmruby环境配置
  • 将淘宝源移除,用ruby-china替换

一、安装rvm环境

  • 检查rvm环境,终端输入指令:
rvm -v
  • 输出(如果输出如下内容证明不存在rvm环境,如果存在请跳过此步骤)
-bash: rvm: command not found
  • 安装配置 rvm 环境
curl -L https://get.rvm.io | bash -s stable
  • 安装rvm成功的输出
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    149      0  0:00:01  0:00:01 --:--:--   149
100 24062  100 24062    0     0   1156      0  0:00:20  0:00:20 --:--:--  5092
Downloading 
Downloading 
curl: (7) Failed to connect to  port 443: Operation timed out

Could not download 
curl returned status '7'.

Installing RVM to /Users/wanghongqing/.rvm/
Adding rvm PATH line to /Users/wanghongqing/.profile /Users/wanghongqing/.mkshrc /Users/wanghongqing/.bashrc /Users/wanghongqing/.zshrc.
Adding rvm loading line to /Users/wanghongqing/.profile /Users/wanghongqing/.bash_profile /Users/wanghongqing/.zlogin.
Installation of RVM in /Users/wanghongqing/.rvm/ is almost complete:

* To start using RVM you need to run `source /Users/wanghongqing/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.

# hongqingWang,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: https://rvm.io/help and 

2017/09/26 增加内容

如果是第一次安装,出现的结果是下面的样子

Installing RVM to /Users/wanghongqing/.rvm/
    Adding rvm PATH line to /Users/wanghongqing/.profile /Users/wanghongqing/.mkshrc /Users/wanghongqing/.bashrc /Users/wanghongqing/.zshrc.
    Adding rvm loading line to /Users/wanghongqing/.profile /Users/wanghongqing/.bash_profile /Users/wanghongqing/.zlogin.
Installation of RVM in /Users/wanghongqing/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/wanghongqing/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
wanghongqingdeMac-mini:~ wanghongqing$ 
  • 重新载入rvm环境
    source ~/.rvm/scripts/rvm
  1. 再次检查rvm环境配置状态
    rvm -v

2017/09/26 更新

rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

二、安装 ruby 环境

*Tips:
如果ruby的版本低于2.2.2,安装CocoaPods会报错,所以建议先升级ruby环境,建议升级到2.3.0以上版本。

  1. 查询当前ruby环境
    ruby -v

  2. 获取到当前版本号
    ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

  3. 查询已知的ruby环境
    rvm list known

  4. 输出查询结果
    # 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[.10]
    [ruby-]2.2[.6]
    [ruby-]2.3[.3]
    [ruby-]2.4[.0]
    ruby-head

     # for forks use: rvm install ruby-head-<name> --url  --branch 2.2
     
     # JRuby
     jruby-1.6[.8]
     jruby-1.7[.26]
     jruby[-9.1.7.0]
     jruby-head
     
     # Rubinius
     rbx-1[.4.3]
     rbx-2.3[.0]
     rbx-2.4[.1]
     rbx-2[.5.8]
     rbx[-3.71]
     rbx-head
     
     # Opal
     opal
     
     # Minimalistic ruby implementation - ISO 30170:2012
     mruby-1.0.0
     mruby-1.1.0
     mruby-1[.2.0]
     mruby[-head]
     
     # Ruby Enterprise Edition
     ree-1.8.6
     ree[-1.8.7][-2012.02]
     
     # 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
    
  1. 指定ruby版本进行更新
    rvm install 2.3.0

接下来要进行两次Enter确认,一次输入管理员密码

  • 5.1 第一次Enter确认
    Searching for binary rubies, this might take some time.
    No binary rubies available for: osx/10.12/x86_64/ruby-2.3.0.
    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)
    :
  • 5.2 第一次Enter确认后输出,再提示第二次Enter确认
    ==> This script will install:
    /usr/local/bin/brew
    /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
    /usr/local/Homebrew
    ==> The following existing directories will be made group writable:
    /usr/local/bin
    /usr/local/sbin
    ==> The following existing directories will have their owner set to wanghongqing:
    /usr/local/bin
    /usr/local/sbin
    ==> The following existing directories will have their group set to admin:
    /usr/local/bin
    /usr/local/sbin
    ==> The following new directories will be created:
    /usr/local/Cellar
    /usr/local/Homebrew
    /usr/local/Frameworks
    /usr/local/etc
    /usr/local/include
    /usr/local/lib
    /usr/local/opt
    /usr/local/share
    /usr/local/share/zsh
    /usr/local/share/zsh/site-functions
    /usr/local/var

    Press RETURN to continue or any other key to abort
    
  • 5.3 提示输入管理员密码
    ==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin /usr/local/sbin
    Password:


6.输入管理员密码后进行安装ruby 2.3.0版本

==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin /usr/local/sbin
==> /usr/bin/sudo /usr/sbin/chown wanghongqing /usr/local/bin /usr/local/sbin
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/sbin
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown wanghongqing /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/mkdir -p /Users/wanghongqing/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/wanghongqing/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown wanghongqing /Users/wanghongqing/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown wanghongqing /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 6228, done.
remote: Compressing objects: 100% (3808/3808), done.
remote: Total 6228 (delta 3554), reused 4119 (delta 2223), pack-reused 0
Receiving objects: 100% (6228/6228), 3.55 MiB | 557.00 KiB/s, done.
Resolving deltas: 100% (3554/3554), done.
From 
* [new branch]      master     -> origin/master
* [new tag]         0.1        -> 0.1
* [new tag]         0.2        -> 0.2
* [new tag]         0.3        -> 0.3
* [new tag]         0.4        -> 0.4
* [new tag]         0.5        -> 0.5
* [new tag]         0.6        -> 0.6
* [new tag]         0.7        -> 0.7
* [new tag]         0.7.1      -> 0.7.1
* [new tag]         0.8        -> 0.8
* [new tag]         0.8.1      -> 0.8.1
* [new tag]         0.9        -> 0.9
* [new tag]         0.9.1      -> 0.9.1
* [new tag]         0.9.2      -> 0.9.2
* [new tag]         0.9.3      -> 0.9.3
* [new tag]         0.9.4      -> 0.9.4
* [new tag]         0.9.5      -> 0.9.5
* [new tag]         0.9.8      -> 0.9.8
* [new tag]         0.9.9      -> 0.9.9
* [new tag]         1.0.0      -> 1.0.0
* [new tag]         1.0.1      -> 1.0.1
* [new tag]         1.0.2      -> 1.0.2
* [new tag]         1.0.3      -> 1.0.3
* [new tag]         1.0.4      -> 1.0.4
* [new tag]         1.0.5      -> 1.0.5
* [new tag]         1.0.6      -> 1.0.6
* [new tag]         1.0.7      -> 1.0.7
* [new tag]         1.0.8      -> 1.0.8
* [new tag]         1.0.9      -> 1.0.9
* [new tag]         1.1.0      -> 1.1.0
* [new tag]         1.1.1      -> 1.1.1
* [new tag]         1.1.10     -> 1.1.10
* [new tag]         1.1.11     -> 1.1.11
* [new tag]         1.1.12     -> 1.1.12
* [new tag]         1.1.13     -> 1.1.13
* [new tag]         1.1.2      -> 1.1.2
* [new tag]         1.1.3      -> 1.1.3
* [new tag]         1.1.4      -> 1.1.4
* [new tag]         1.1.5      -> 1.1.5
* [new tag]         1.1.6      -> 1.1.6
* [new tag]         1.1.7      -> 1.1.7
* [new tag]         1.1.8      -> 1.1.8
* [new tag]         1.1.9      -> 1.1.9
* [new tag]         1.2.0      -> 1.2.0
* [new tag]         1.2.1      -> 1.2.1
HEAD is now at 1765062 Merge pull request #2700 from sjackman/env-std-linux
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 4427, done.
remote: Compressing objects: 100% (4231/4231), done.
remote: Total 4427 (delta 36), reused 469 (delta 14), pack-reused 0
Receiving objects: 100% (4427/4427), 3.52 MiB | 182.00 KiB/s, done.
Resolving deltas: 100% (36/36), done.
Tapped 4230 formulae (4,470 files, 11MB)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/wanghongqing/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
http://docs.brew.sh/Analytics.html

==> Next steps:
- Run `brew help` to get started
- Further documentation:
http://docs.brew.sh
Installing requirements for osx.
Updating system.........
Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, readline, libksba, openssl..........
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/wanghongqing/.rvm/rubies/ruby-2.3.0, this may take a while depending on your cpu(s)...
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
0 13.5M    0 81920    0     0     85      0 46:21:29  0:16:00 46:05:29     0
curl: (56) SSLRead() return error -9806
There was an error(56).
Checking fallback: https://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2
No fallback URL could be found, try increasing timeout with:

echo "export rvm_max_time_flag=20" >> ~/.rvmrc

There has been an error fetching the ruby interpreter. Halting the installation.

此处我还没有查明到底是因为什么报错,但是我关闭Terminal以后,再次安装的时候就可以正常安装了。

7.重新执行安装命令

rvm install 2.3.0
Error running '__rvm_make -j 1',
please read /Users/wanghongqing/.rvm/log/1506477257_ruby-2.3.0/make.log
There has been an error while running make. Halting the installation.

8.安装成功输出(再次安装就不需要再执行两次Enter及输入管理员密码了)

Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.12/x86_64/ruby-2.3.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/wanghongqing/.rvm/rubies/ruby-2.3.0, this may take a while depending on your cpu(s)...
ruby-2.3.0 - #downloading ruby-2.3.0, this may take a while depending on your connection...
** Resuming transfer from byte position 81920
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100 13.4M  100 13.4M    0     0  27376      0  0:08:35  0:08:35 --:--:-- 37898
ruby-2.3.0 - #extracting ruby-2.3.0 to /Users/wanghongqing/.rvm/src/ruby-2.3.0.-
ruby-2.3.0 - #applying patch /Users/wanghongqing/.rvm/patches/ruby/changeset_r53419.diff.
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..
ruby-2.3.0 - #downloading rubygems-2.6.12
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  749k  100  749k    0     0  41534      0  0:00:18  0:00:18 --:--:-- 44241
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.3.0 - #extracting rubygems-2.6.12....
ruby-2.3.0 - #removing old rubygems.........
ruby-2.3.0 - #installing rubygems-2.6.12.........................
ruby-2.3.0 - #gemset created /Users/wanghongqing/.rvm/gems/ruby-2.3.0@global
ruby-2.3.0 - #importing gemset /Users/wanghongqing/.rvm/gemsets/global.gems....|
ruby-2.3.0 - #generating global wrappers........
ruby-2.3.0 - #gemset created /Users/wanghongqing/.rvm/gems/ruby-2.3.0
ruby-2.3.0 - #importing gemsetfile /Users/wanghongqing/.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版本号
gem -v
  • 如果版本低于2.6.x建议升级(此处我的版本是2.6.12
2.6.12
  • 如需升级,执行以下命令
gem update --system

提示error没有权限更新

Updating rubygems-update
Fetching: rubygems-update-2.6.13.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

以管理员身份执行

sudo gem update --system

成功

Password:
Updating rubygems-update
Fetching: rubygems-update-2.6.13.gem (100%)
Successfully installed rubygems-update-2.6.13
Parsing documentation for rubygems-update-2.6.13
Installing ri documentation for rubygems-update-2.6.13
Installing darkfish documentation for rubygems-update-2.6.13
Installing RubyGems 2.6.13
RubyGems 2.6.13 installed
Parsing documentation for rubygems-2.6.13
Installing ri documentation for rubygems-2.6.13

=== 2.6.13 / 2017-08-27

Security fixes:

* Fix a DNS request hijacking vulnerability.
  Fix by Samuel Giddins.
* Fix an ANSI escape sequence vulnerability.
  Fix by Evan Phoenix.
* Fix a DOS vulernerability in the `query` command.
  Fix by Samuel Giddins.
* Fix a vulnerability in the gem installer that allowed
  a malicious gem to overwrite arbitrary files.
  Fix by Samuel Giddins.

=== 2.6.12 / 2017-04-30

Bug fixes:

* Fix test_self_find_files_with_gemfile to sort expected files. Pull
  request #1880 by Kazuaki Matsuo.
* Fix issue for MinGW / MSYS2 builds and testing. Pull request #1879 by
  MSP-Greg.
* Fix gem open to open highest version number rather than lowest. Pull
  request #1877 by Tim Pope.
* Add a test for requiring a default spec as installed by the ruby
  installer. Pull request #1899 by Samuel Giddins.
* Fix broken --exact parameter to gem command. Pull request #1873 by Jason
  Frey.
* [Installer] Generate backwards-compatible binstubs. Pull request #1904
  by Samuel Giddins.
* Fix pre-existing source recognition on add action. Pull request #1883 by
  Jonathan Claudius.
* Prevent negative IDs in output of #inspect. Pull request #1908 by Vít
  Ondruch.
* Allow Gem.finish_resolve to respect already-activated specs. Pull
  request #1910 by Samuel Giddins.

=== 2.6.11 / 2017-03-16

Bug fixes:

* Fixed broken tests on ruby-head. Pull request #1841 by
  SHIBATA Hiroshi.
* Update vendored Molinillo to 0.5.7. Pull request #1859 by Samuel
  Giddins.
* Avoid activating Ruby 2.5 default gems when possible. Pull request #1843
  by Samuel Giddins.
* Use improved resolver sorting algorithm. Pull request #1856 by
  Samuel Giddins.

=== 2.6.10 / 2017-01-23

Bug fixes:

* Fix `require` calling the wrong `gem` method when it is overridden.
  Pull request #1822 by Samuel Giddins.

=== 2.6.9 / 2017-01-20

Bug fixes:

* Allow initializing versions with empty strings. Pull request #1767 by
  Luis Sagastume.
* Fix TypeError on 2.4. Pull request #1788 by Nobuyoshi Nakada.
* Don't output mkmf.log message if compilation didn't fail. Pull request
  #1808 by Jeremy Evans.
* Fixed broken links and overzealous URL encoding in gem server. Pull
  request #1809 by Nicole Orchard.
* Update vendored Molinillo to 0.5.5. Pull request #1812 by Samuel
  Giddins.
* RakeBuilder: avoid frozen string issue. Pull request #1819 by Olle
  Jonsson.

=== 2.6.8 / 2016-10-29

Bug fixes:

* Improve SSL verification failure message. Pull request #1751
  by Eric Hodel.
* Ensure `to_spec` falls back on prerelease specs. Pull request
  #1755 by André Arko.
* Update vendored Molinillo to 0.5.3. Pull request #1763 by
  Samuel Giddins.

=== 2.6.7 / 2016-09-26

Bug fixes:

* Install native extensions in the correct location when using the
  `--user-install` flag. Pull request #1683 by Noah Kantrowitz.
* When calling `Gem.sources`, load sources from `configuration`
  if present, else use the default sources. Pull request #1699
  by Luis Sagastume.
* Fail gracefully when attempting to redirect without a Location.
  Pull request #1711 by Samuel Giddins.
* Update vendored Molinillo to 0.5.1. Pull request #1714 by
  Samuel Giddins.

=== 2.6.6 / 2016-06-22

Bug fixes:

* Sort installed versions to make sure we install the latest version when
  running `gem update --system`. As a one-time fix, run
  `gem update --system=2.6.6`. Pull request #1601 by David Radcliffe.

=== 2.6.5 / 2016-06-21

Minor enhancements:

* Support for unified Integer in Ruby 2.4. Pull request #1618
  by SHIBATA Hiroshi.
* Update vendored Molinillo to 0.5.0 for performance improvements.
  Pull request #1638 by Samuel Giddins.

Bug fixes:

* Raise an explicit error if Signer#sign is called with no certs. Pull
  request #1605 by Daniel Berger.
* Update `update_bundled_ca_certificates` utility script for directory
  nesting. Pull request #1583 by James Wen.
* Fix broken symlink support in tar writer (+ fix broken test). Pull
  request #1578 by Cezary Baginski.
* Remove extension directory before (re-)installing. Pull request #1576
  by Jeremy Hinegardner.
* Regenerate test CA certificates with appropriate extensions. Pull
  request #1611 by rhenium.
* Rubygems does not terminate on failed file lock when not superuser. Pull
  request #1582 by Ellen Marie Dash.
* Fix tar headers with a 101 character name. Pull request #1612 by Paweł
  Tomulik.
* Add Gem.platform_defaults to allow implementations to override defaults.
  Pull request #1644 by Charles Oliver Nutter.
* Run Bundler tests on TravisCI. Pull request #1650 by Samuel Giddins.

=== 2.6.4 / 2016-04-26

Minor enhancements:

* Use Gem::Util::NULL_DEVICE instead of hard coded strings. Pull request #1588
  by Chris Charabaruk.
* Use File.symlink on MS Windows if supported. Pull request #1418
  by Nobuyoshi Nakada.

Bug fixes:

* Redact uri password from error output when gem fetch fails. Pull request
  #1565 by Brian Fletcher.
* Suppress warnings. Pull request #1594 by Nobuyoshi Nakada.
* Escape user-supplied content served on web pages by `gem server` to avoid
  potential XSS vulnerabilities. Samuel Giddins.

=== 2.6.3 / 2016-04-05

Minor enhancements:

* Lazily calculate Gem::LoadError exception messages. Pull request #1550
  by Aaron Patterson.
* New fastly cert. Pull request #1548 by David Radcliffe.
* Organize and cleanup SSL certs. Pull request #1555 by James Wen.
* [RubyGems] Make deprecation message for paths= more helpful. Pull
  request #1562 by Samuel Giddins.
* Show default gems when using "gem list". Pull request #1570 by Luis
  Sagastume.

Bug fixes:

* Stub ordering should be consistent regardless of how cache is populated.
  Pull request #1552 by Aaron Patterson.
* Handle cases when the @@stubs variable contains non-stubs. Pull request
  #1558 by Per Lundberg.
* Fix test on Windows for inconsistent temp path. Pull request #1554 by
  Hiroshi Shirosaki.
* Fix `Gem.find_spec_for_exe` picks oldest gem. Pull request #1566 by
  Shinichi Maeshima.
* [Owner] Fallback to email and userid when owner email is missing. Pull
  request #1569 by Samuel Giddins.
* [Installer] Handle nil existing executable. Pull request #1561 by Samuel
  Giddins.
* Allow two digit version numbers in the tests. Pull request #1575 by unak.

=== 2.6.2 / 2016-03-12

Bug fixes:

* Fix wrong version of gem activation for bin stub. Pull request #1527 by
  Aaron Patterson.
* Speed up gem activation failures. Pull request #1539 by Aaron Patterson.
* Fix platform sorting in the resolver. Pull request #1542 by Samuel E.
  Giddins.
* Ensure we unlock the monitor even if try_activate throws. Pull request
  #1538 by Charles Oliver Nutter.


=== 2.6.1 / 2016-02-28

Bug fixes:

* Ensure `default_path` and `home` are set for paths. Pull request #1513
  by Aaron Patterson.
* Restore but deprecate support for Array values on `Gem.paths=`. Pull
  request #1514 by Aaron Patterson.
* Fix invalid gem file preventing gem install from working. Pull request
  #1499 by Luis Sagastume.

=== 2.6.0 / 2016-02-26

Minor enhancements:

* RubyGems now defaults the `gem push` to the gem's "allowed_push_host"
  metadata setting.  Pull request #1486 by Josh Lane.
* Update bundled Molinillo to 0.4.3. Pull request #1493 by Samuel E. Giddins.
* Add version option to gem open command. Pull request #1483 by Hrvoje
  Šimić.
* Feature/add silent flag. Pull request #1455 by Luis Sagastume.
* Allow specifying gem requirements via env variables. Pull request #1472
  by Samuel E. Giddins.

Bug fixes:

* RubyGems now stores `gem push` credentials under the host you signed-in for.
  Pull request #1485 by Josh Lane.
* Move `coding` location to first line. Pull request #1471 by SHIBATA
  Hiroshi.
* [PathSupport] Handle a regexp path separator. Pull request #1469 by
  Samuel E. Giddins.
* Clean up the PathSupport object. Pull request #1094 by Aaron Patterson.
* Join with File::PATH_SEPARATOR in Gem.use_paths. Pull request #1476 by
  Samuel E. Giddins.
* Handle when the gem home and gem path arent set in the config file. Pull
  request #1478 by Samuel E. Giddins.
* Terminate TimeoutHandler. Pull request #1479 by Nobuyoshi Nakada.
* Remove redundant cache. Pull request #1482 by Eileen M. Uchitelle.
* Freeze `Gem::Version@segments` instance variable. Pull request #1487 by
  Ben Dean.
* Gem cleanup is trying to uninstall gems outside GEM_HOME and reporting
  an error after it tries. Pull request #1353 by Luis Sagastume.
* Avoid duplicated sources. Pull request #1489 by Luis Sagastume.
* Better description for quiet flag. Pull request #1491 by Luis Sagastume.
* Raise error if find_by_name returns with nil. Pull request #1494 by
  Zoltán Hegedüs.
* Find_files only from loaded_gems when using gemdeps. Pull request #1277
  by Michal Papis.


------------------------------------------------------------------------------

RubyGems installed the following executables:
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem

Ruby Interactive (ri) documentation was installed. ri is kind of like man 
pages for ruby libraries. You may access it like this:
  ri Classname
  ri Classname.class_method
  ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
'gem help env' for details.

RubyGems system software updated
  • 检查ruby
gem sources -l
  • 检查结果
*** CURRENT SOURCES ***

https://ruby.taobao.org/
  • 我这里用淘宝源替换过,如果没替换过应该是下面的
*** CURRENT SOURCES ***

https://rubygems.org/

移除gem

gem sources --remove https://rubygems.org/

结果

https://rubygems.org/ removed from sources

如果你也曾经安装过淘宝源,请看下面

  • 因为淘宝源(2016年06月)已经停止维护,所以建议使用,所以移除原来的淘宝源
gem sources --remove https://ruby.taobao.org/

这里我执行这个命令,总报下面的错误

ERROR:  While executing gem ... (Errno::EACCES)
Permission denied @ rb_sysopen - /Users/wanghongqing/.gemrc

在网上找了很多办法都没解决

说法是:你是用普通用户,运行了系统上的 rvm,而无法去存取系统上的目录。
但是我按照网上的方法并没有很好的解决。

而我的做法是以管理员的身份执行这句命令

sudo gem source --remove https://ruby.taobao.org/

就成功的移除了淘宝源

https://ruby.taobao.org/ removed from sources
  • 添加ruby-china
gem source --add https://gems.ruby-china.org

如果遇到同样的问题,还是以管理员身份添加就好了


四、安装 Cocoapods

  • 终端执行命令,以管理员的身份安装
sudo gem install cocoapods
  1. 安装成功(出现gems installed证明安装成功)
    Fetching: nanaimo-0.2.3.gem (100%)
    Successfully installed nanaimo-0.2.3
    Fetching: colored2-3.1.2.gem (100%)
    Successfully installed colored2-3.1.2
    Fetching: claide-1.0.2.gem (100%)
    Successfully installed claide-1.0.2
    Fetching: CFPropertyList-2.3.5.gem (100%)
    Successfully installed CFPropertyList-2.3.5
    Fetching: xcodeproj-1.5.0.gem (100%)
    Successfully installed xcodeproj-1.5.0
    Fetching: ruby-macho-1.1.0.gem (100%)
    Successfully installed ruby-macho-1.1.0
    Fetching: nap-1.1.0.gem (100%)
    Successfully installed nap-1.1.0
    Fetching: molinillo-0.5.7.gem (100%)
    Successfully installed molinillo-0.5.7
    Fetching: gh_inspector-1.0.3.gem (100%)
    Successfully installed gh_inspector-1.0.3
    Fetching: fourflusher-2.0.1.gem (100%)
    Successfully installed fourflusher-2.0.1
    Fetching: escape-0.0.4.gem (100%)
    Successfully installed escape-0.0.4
    Fetching: cocoapods-try-1.1.0.gem (100%)
    Successfully installed cocoapods-try-1.1.0
    Fetching: netrc-0.7.8.gem (100%)
    Successfully installed netrc-0.7.8
    Fetching: cocoapods-trunk-1.2.0.gem (100%)
    Successfully installed cocoapods-trunk-1.2.0
    Fetching: cocoapods-stats-1.0.0.gem (100%)
    Successfully installed cocoapods-stats-1.0.0
    Fetching: cocoapods-search-1.0.0.gem (100%)
    Successfully installed cocoapods-search-1.0.0
    Fetching: cocoapods-plugins-1.0.0.gem (100%)
    Successfully installed cocoapods-plugins-1.0.0
    Fetching: cocoapods-downloader-1.1.3.gem (100%)
    Successfully installed cocoapods-downloader-1.1.3
    Fetching: cocoapods-deintegrate-1.0.1.gem (100%)
    Successfully installed cocoapods-deintegrate-1.0.1
    Fetching: fuzzy_match-2.0.4.gem (100%)
    Successfully installed fuzzy_match-2.0.4
    Fetching: thread_safe-0.3.6.gem (100%)
    Successfully installed thread_safe-0.3.6
    Fetching: tzinfo-1.2.3.gem (100%)
    Successfully installed tzinfo-1.2.3
    Fetching: i18n-0.8.4.gem (100%)
    Successfully installed i18n-0.8.4
    Fetching: activesupport-4.2.8.gem (100%)
    Successfully installed activesupport-4.2.8
    Fetching: cocoapods-core-1.2.1.gem (100%)
    Successfully installed cocoapods-core-1.2.1
    Fetching: cocoapods-1.2.1.gem (100%)
    Successfully installed cocoapods-1.2.1
    Parsing documentation for nanaimo-0.2.3
    Installing ri documentation for nanaimo-0.2.3
    Parsing documentation for colored2-3.1.2
    Installing ri documentation for colored2-3.1.2
    Parsing documentation for claide-1.0.2
    Installing ri documentation for claide-1.0.2
    Parsing documentation for CFPropertyList-2.3.5
    Installing ri documentation for CFPropertyList-2.3.5
    Parsing documentation for xcodeproj-1.5.0
    Installing ri documentation for xcodeproj-1.5.0
    Parsing documentation for ruby-macho-1.1.0
    Installing ri documentation for ruby-macho-1.1.0
    Parsing documentation for nap-1.1.0
    Installing ri documentation for nap-1.1.0
    Parsing documentation for molinillo-0.5.7
    Installing ri documentation for molinillo-0.5.7
    Parsing documentation for gh_inspector-1.0.3
    Installing ri documentation for gh_inspector-1.0.3
    Parsing documentation for fourflusher-2.0.1
    Installing ri documentation for fourflusher-2.0.1
    Parsing documentation for escape-0.0.4
    Installing ri documentation for escape-0.0.4
    Parsing documentation for cocoapods-try-1.1.0
    Installing ri documentation for cocoapods-try-1.1.0
    Parsing documentation for netrc-0.7.8
    Installing ri documentation for netrc-0.7.8
    Parsing documentation for cocoapods-trunk-1.2.0
    Installing ri documentation for cocoapods-trunk-1.2.0
    Parsing documentation for cocoapods-stats-1.0.0
    Installing ri documentation for cocoapods-stats-1.0.0
    Parsing documentation for cocoapods-search-1.0.0
    Installing ri documentation for cocoapods-search-1.0.0
    Parsing documentation for cocoapods-plugins-1.0.0
    Installing ri documentation for cocoapods-plugins-1.0.0
    Parsing documentation for cocoapods-downloader-1.1.3
    Installing ri documentation for cocoapods-downloader-1.1.3
    Parsing documentation for cocoapods-deintegrate-1.0.1
    Installing ri documentation for cocoapods-deintegrate-1.0.1
    Parsing documentation for fuzzy_match-2.0.4
    Installing ri documentation for fuzzy_match-2.0.4
    Parsing documentation for thread_safe-0.3.6
    Installing ri documentation for thread_safe-0.3.6
    Parsing documentation for tzinfo-1.2.3
    Installing ri documentation for tzinfo-1.2.3
    Parsing documentation for i18n-0.8.4
    Installing ri documentation for i18n-0.8.4
    Parsing documentation for activesupport-4.2.8
    Installing ri documentation for activesupport-4.2.8
    Parsing documentation for cocoapods-core-1.2.1
    Installing ri documentation for cocoapods-core-1.2.1
    Parsing documentation for cocoapods-1.2.1
    Installing ri documentation for cocoapods-1.2.1
    Done installing documentation for nanaimo, colored2, claide, CFPropertyList, xcodeproj, ruby-macho, nap, molinillo, gh_inspector, fourflusher, escape, cocoapods-try, netrc, cocoapods-trunk, cocoapods-stats, cocoapods-search, cocoapods-plugins, cocoapods-downloader, cocoapods-deintegrate, fuzzy_match, thread_safe, tzinfo, i18n, activesupport, cocoapods-core, cocoapods after 16 seconds
    26 gems installed

如果出现下面度问题

ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/fuzzy_match

更换成下面度安装命令

sudo gem install -n /usr/local/bin cocoapods

成功输出如下

ERROR:  SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR:  You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.3.1.gem (100%)
Successfully installed cocoapods-core-1.3.1
Fetching: claide-1.0.2.gem (100%)
Successfully installed claide-1.0.2
Fetching: cocoapods-deintegrate-1.0.1.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.1
Fetching: cocoapods-downloader-1.1.3.gem (100%)
Successfully installed cocoapods-downloader-1.1.3
Fetching: cocoapods-plugins-1.0.0.gem (100%)
Successfully installed cocoapods-plugins-1.0.0
Fetching: cocoapods-search-1.0.0.gem (100%)
Successfully installed cocoapods-search-1.0.0
Fetching: cocoapods-stats-1.0.0.gem (100%)
Successfully installed cocoapods-stats-1.0.0
Fetching: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-1.2.0.gem (100%)
Successfully installed cocoapods-trunk-1.2.0
Fetching: cocoapods-try-1.1.0.gem (100%)
Successfully installed cocoapods-try-1.1.0
Fetching: molinillo-0.5.7.gem (100%)
Successfully installed molinillo-0.5.7
Fetching: CFPropertyList-2.3.5.gem (100%)
Successfully installed CFPropertyList-2.3.5
Fetching: colored2-3.1.2.gem (100%)
Successfully installed colored2-3.1.2
Fetching: nanaimo-0.2.3.gem (100%)
Successfully installed nanaimo-0.2.3
Fetching: xcodeproj-1.5.2.gem (100%)
Successfully installed xcodeproj-1.5.2
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: fourflusher-2.0.1.gem (100%)
Successfully installed fourflusher-2.0.1
Fetching: gh_inspector-1.0.3.gem (100%)
Successfully installed gh_inspector-1.0.3
Fetching: ruby-macho-1.1.0.gem (100%)
Successfully installed ruby-macho-1.1.0
Fetching: cocoapods-1.3.1.gem (100%)
Successfully installed cocoapods-1.3.1
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-1.3.1
Installing ri documentation for cocoapods-core-1.3.1
Parsing documentation for claide-1.0.2
Installing ri documentation for claide-1.0.2
Parsing documentation for cocoapods-deintegrate-1.0.1
Installing ri documentation for cocoapods-deintegrate-1.0.1
Parsing documentation for cocoapods-downloader-1.1.3
Installing ri documentation for cocoapods-downloader-1.1.3
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-search-1.0.0
Installing ri documentation for cocoapods-search-1.0.0
Parsing documentation for cocoapods-stats-1.0.0
Installing ri documentation for cocoapods-stats-1.0.0
Parsing documentation for netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-1.2.0
Installing ri documentation for cocoapods-trunk-1.2.0
Parsing documentation for cocoapods-try-1.1.0
Installing ri documentation for cocoapods-try-1.1.0
Parsing documentation for molinillo-0.5.7
Installing ri documentation for molinillo-0.5.7
Parsing documentation for CFPropertyList-2.3.5
Installing ri documentation for CFPropertyList-2.3.5
Parsing documentation for colored2-3.1.2
Installing ri documentation for colored2-3.1.2
Parsing documentation for nanaimo-0.2.3
Installing ri documentation for nanaimo-0.2.3
Parsing documentation for xcodeproj-1.5.2
Installing ri documentation for xcodeproj-1.5.2
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-2.0.1
Installing ri documentation for fourflusher-2.0.1
Parsing documentation for gh_inspector-1.0.3
Installing ri documentation for gh_inspector-1.0.3
Parsing documentation for ruby-macho-1.1.0
Installing ri documentation for ruby-macho-1.1.0
Parsing documentation for cocoapods-1.3.1
Installing ri documentation for cocoapods-1.3.1
21 gems installed

五、设置 Cocoapods

  • 终端输入指令
pod setup

安装完成以后的输出

Setting up CocoaPods master repo
  $ /usr/bin/git clone  master --progress
  Cloning into 'master'...
  remote: Counting objects: 1563147, done.        
  remote: Compressing objects: 100% (3192/3192), done.        
  remote: Total 1563147 (delta 2286), reused 2844 (delta 1169), pack-reused 1558582        
  Receiving objects: 100% (1563147/1563147), 428.32 MiB | 78.00 KiB/s, done.
  Resolving deltas: 100% (822273/822273), done.
  Checking out files: 100% (184860/184860), done.

CocoaPods 1.4.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at 

Setup completed
这里曾经我遇到过一个面试题,题目大概是:当执行pod setup时,实际上发生了什么?可惜当时我没有答上,现在补上,希望可以帮助到别人和自己。*

六、使用 Cocoapods 给项目安装第三方框架

  • 新建一个项目到桌面,并切换到该项目目录下
  • 初始化项目,生成Podfile文件
pod init
  • Xcode编辑Podfile文件
  • 模糊搜索第三方框架
pod search afn

如果之前的ruby环境配置不正确的话,搜索到可能会是这样的情况:

/Library/Ruby/Site/2.0.0/rubygems.rb:250:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
from /Library/Ruby/Site/2.0.0/rubygems.rb:278:in `activate_bin_path'
from /usr/local/bin/pod:22:in `<main>'
  • 搜索afn的结果
  • Podfile文件中添加第三方框架
pod 'AFNetworking'

7.安装框架第三方框架AFNetworking(第一次使用时,可能会等待十几分钟的时间)

pod install

8.安装框架第三方框架,不更新本地索引,速度快

pod install --no-repo-update

10.CocoaPods 在执行pod installpod update时,会默认先更新一次podspec索引。使用--no-repo-update参数可以禁止其做索引更新操作。如下所示:

pod install --no-repo-update
pod update --no-repo-update

11.删除第三方框架

  • Podfile文件中,删除对应第三方框架

    pod 'AFNetworking'
    
  • 然后

    pod update
    

六、关于 Podfile.lock

This file should always be kept under version control.

七、CocoaPods的原理: