Xcode7.3 安装cocoapods 失败问题解决

来源:互联网 发布:vr编辑软件 编辑:程序博客网 时间:2024/06/05 08:17
<code class="hljs http has-numbering"><span class="hljs-attribute" style="color: rgb(163, 21, 21);"></span></code>
ERROR:  Error installing cocoapods:activesupport requires Ruby version >= 2.2.2.
说明Ruby环境需要升级更新, 我以mac OS 10.11.5 更新ruby方法为例, 更新Ruby环境安装cocoapods的详细步骤:
终端成功安装cocoapods详细步骤:

Last login: Thu Jul 14 08:57:44 on console
TuFa-Mac:~ TuFa$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
TuFa-Mac:~ TuFa$ gem sources --remove https://rubygems.org/
source https://rubygems.org/ not present in cache
TuFa-Mac:~ TuFa$ gem sources -a https://ruby.taobao.org/ 
source https://ruby.taobao.org/ already present in the cache
TuFa-Mac:~ TuFa$ gem sources -l
*** CURRENT SOURCES ***


https://ruby.taobao.org/
TuFa-Mac:~ TuFa$ sudo gem install cocoapods
Password:
ERROR:  Error installing cocoapods:
activesupport requires Ruby version >= 2.2.2.

TuFa-Mac:~ TuFa$ curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Couldn't connect to server
TuFa-Mac:~ TuFa$ ping
usage: ping [-AaDdfnoQqRrv] [-b boundif] [-c count] [-G sweepmaxsize]
            [-g sweepminsize] [-h sweepincrsize] [-i wait] [−k trafficclass]
            [-l preload] [-M mask | time] [-m ttl] [-p pattern]
            [-S src_addr] [-s packetsize] [-t timeout][-W waittime] [-z tos]
            host
       ping [-AaDdfLnoQqRrv] [-b boundif] [-c count] [-I iface] [-i wait]
            [−k trafficclass] [-l preload] [-M mask | time] [-m ttl] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
            [-z tos] mcast-group
TuFa-Mac:~ TuFa$ curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   184  100   184    0     0    148      0  0:00:01  0:00:01 --:--:--   148
100 22865  100 22865    0     0   2919      0  0:00:07  0:00:07 --:--:--  5645
Downloading https://github.com/rvm/rvm/archive/1.27.0.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.27.0/1.27.0.tar.gz.asc',
but no GPG software exists to validate it, skipping.


Upgrading the RVM installation in /Users/apple/.rvm/
    RVM PATH line found in /Users/apple/.mkshrc /Users/apple/.profile /Users/apple/.bashrc /Users/apple/.zshrc.
    RVM sourcing line found in /Users/apple/.profile /Users/apple/.bash_profile /Users/apple/.zlogin.
Upgrade of RVM in /Users/apple/.rvm/ is complete.


# tf1106285167,
#
#   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 https://twitter.com/rvm_io


Upgrade Notes:


  * No new notes to display.


TuFa-Mac:~ TuFa$ source ~/.bashrc
TuFa-Mac:~ TuFa$ source ~/.bash_profile
TuFa-Mac:~ TuFa$ source ~/.profile
TuFa-Mac:~ TuFa$ rvm -v
rvm 1.27.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
TuFa-Mac:~ TuFa$  ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
TuFa-Mac:~ TuFa$ 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
TuFa-Mac:~ TuFa$ rvm install 2.3
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.11/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)
: /usr/local/bin/brew
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   124    0   124    0     0     56      0 --:--:--  0:00:02 --:--:--    56
100   139    0   139    0     0     52      0 --:--:--  0:00:02 --:--:--    52
100  194k  100  194k    0     0  27328      0  0:00:07  0:00:07 --:--:-- 47763
Installing requirements for osx.
Updating system......
Installing required packages: autoconf, automake, libtool, pkg-config, libyaml, readline, libksba, openssl..........
Certificates in '/usr/local/bin/brew/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/apple/.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
100 13.5M  100 13.5M    0     0  53901      0  0:04:23  0:04:23 --:--:-- 90154
ruby-2.3.0 - #extracting ruby-2.3.0 to /Users/apple/.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/apple/.rvm/gems/ruby-2.3.0@global
ruby-2.3.0 - #importing gemset /Users/apple/.rvm/gemsets/global.gems...........|
ruby-2.3.0 - #generating global wrappers........
ruby-2.3.0 - #gemset created /Users/apple/.rvm/gems/ruby-2.3.0
ruby-2.3.0 - #importing gemsetfile /Users/apple/.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
TuFa-Mac:~ TuFa$ sudo gem install cocoapods
Password:
Fetching: i18n-0.7.0.gem (100%)
Successfully installed i18n-0.7.0
Fetching: thread_safe-0.3.5.gem (100%)
Successfully installed thread_safe-0.3.5
Fetching: tzinfo-1.2.2.gem (100%)
Successfully installed tzinfo-1.2.2
Fetching: concurrent-ruby-1.0.2.gem (100%)
Successfully installed concurrent-ruby-1.0.2
Fetching: activesupport-5.0.0.gem (100%)
Successfully installed activesupport-5.0.0
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-1.0.1.gem (100%)
Successfully installed cocoapods-core-1.0.1
Fetching: claide-1.0.0.gem (100%)
Successfully installed claide-1.0.0
Fetching: cocoapods-deintegrate-1.0.0.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.0
Fetching: cocoapods-downloader-1.1.0.gem (100%)
Successfully installed cocoapods-downloader-1.1.0
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.0.0.gem (100%)
Successfully installed cocoapods-trunk-1.0.0
Fetching: cocoapods-try-1.1.0.gem (100%)
Successfully installed cocoapods-try-1.1.0
Fetching: molinillo-0.4.5.gem (100%)
Successfully installed molinillo-0.4.5
Fetching: colored-1.2.gem (100%)
Successfully installed colored-1.2
Fetching: xcodeproj-1.2.0.gem (100%)
Successfully installed xcodeproj-1.2.0
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: fourflusher-0.3.2.gem (100%)
Successfully installed fourflusher-0.3.2
Fetching: cocoapods-1.0.1.gem (100%)
Successfully installed cocoapods-1.0.1
Parsing documentation for i18n-0.7.0
Installing ri documentation for i18n-0.7.0
Parsing documentation for thread_safe-0.3.5
Installing ri documentation for thread_safe-0.3.5
Parsing documentation for tzinfo-1.2.2
Installing ri documentation for tzinfo-1.2.2
Parsing documentation for concurrent-ruby-1.0.2
Installing ri documentation for concurrent-ruby-1.0.2
Parsing documentation for activesupport-5.0.0
Installing ri documentation for activesupport-5.0.0
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for cocoapods-core-1.0.1
Installing ri documentation for cocoapods-core-1.0.1
Parsing documentation for claide-1.0.0
Installing ri documentation for claide-1.0.0
Parsing documentation for cocoapods-deintegrate-1.0.0
Installing ri documentation for cocoapods-deintegrate-1.0.0
Parsing documentation for cocoapods-downloader-1.1.0
Installing ri documentation for cocoapods-downloader-1.1.0
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.0.0
Installing ri documentation for cocoapods-trunk-1.0.0
Parsing documentation for cocoapods-try-1.1.0
Installing ri documentation for cocoapods-try-1.1.0
Parsing documentation for molinillo-0.4.5
Installing ri documentation for molinillo-0.4.5
Parsing documentation for colored-1.2
Installing ri documentation for colored-1.2
Parsing documentation for xcodeproj-1.2.0
Installing ri documentation for xcodeproj-1.2.0
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-0.3.2
Installing ri documentation for fourflusher-0.3.2
Parsing documentation for cocoapods-1.0.1
Installing ri documentation for cocoapods-1.0.1
Done installing documentation for i18n, thread_safe, tzinfo, concurrent-ruby, activesupport, nap, fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, colored, xcodeproj, escape, fourflusher, cocoapods after 54 seconds
23 gems installed
TuFa-Mac:~ TuFa$ pod search AFNetworking
Setting up CocoaPods master repo
pod setup
Setup completed
Creating search index for spec repo 'master'.. Done!




-> AFNetworking (3.1.0)
   A delightful iOS and OS X networking framework.
   pod 'AFNetworking', '~> 3.1.0'
   - Homepage: https://github.com/AFNetworking/AFNetworking
   - Source:   https://github.com/AFNetworking/AFNetworking.git
   - Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,
   3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,
   2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,
   2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,
   1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,
   1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]
   - Subspecs:
     - AFNetworking/Serialization (3.1.0)
     - AFNetworking/Security (3.1.0)
     - AFNetworking/Reachability (3.1.0)
     - AFNetworking/NSURLSession (3.1.0)
     - AFNetworking/UIKit (3.1.0)


-> AFNetworking+AutoRetry (0.0.5)
   Auto Retries for AFNetworking requests
   pod 'AFNetworking+AutoRetry', '~> 0.0.5'
   - Homepage: https://github.com/shaioz/AFNetworking-AutoRetry
:

    ......

    至此cocoapods安装成功


    Cocoapods使用

    1.使用search命令搜索类库名

    $ pod search AFNetworking
    得到结果如下图:
    从这个图上,我们看到AFN有好多版本,最新的版本是2.6.0.

    2.打开xcode,新建一个工程,工程名为CocoapodsSample。

    使用命令cd,cd后面跟的是工程目录名,可以直接拉进来,

    回车后,输入命令创建Podfile文件

    $ touch Podfile

    我们可以看到,在根目录下,多了一个Podfile文件

    3.使用vim编辑podfile文件,使用命令

    $ vim Podfile

    然后在Podfile文件中输入以下文字:

    platform :ios, '7.0'
    pod "AFNetworking""2.5.0"

    这两句文字的意思是,当前AFNetworking支持的iOS最高版本是iOS 7.0, 要下载的AFNetworking版本是2.5.0。


    ————>出错1:
    [!]Your Podfile has had smart quotes sanitised.To avoid issues in the future,you shouldnot use TextEdit for editing it.If you are not using TextEdit,you should turn off smart quotesin your editor of choice.
    ————>解决:
    platform :ios, '7.0'
    use_frameworks!
    target "Cocoapod_03" do
    pod "AFNetworking", "3.0"
    end

    (Cocoapod_03是项目名称)

    在编辑完后按 esc,然后按":",这个时候输入wq保存退出。

    这个时候打开Podfile文件就会看到里面添加了刚才在终端输入的两行语句,如下图

    4.这时候,你就可以利用CocoPods下载AFNetworking类库了。还是在终端中的当前项目目录下,运行以下命令:

    $ pod install 

    安装成功后,如下图:

    这个时候,会看到多了一个.xcworkspace工程,以后打开项目就用 CocoapodsSample.xcworkspace 打开,而不是之前的.xcodeproj文件。


    5.打开 CocoapodsSample.xcworkspace 工程,你会惊喜地发现,AFNetwoking已经成功导入项目了。
    现在,你就可以开始使用AFNetworking.h啦。

    ———>出错2:(装了多个Xcode导致路径变了)
    ———>解决2:  (1).   sudo xcode-select -switch/Applications/Xcode6.3.1/Xcode.app 
    (Applications/Xcode6.3.1/Xcode.app —>Xcode所在路径)
                             (2).  pod install

    若此后要添加则:
    platform :ios, '7.0'
    use_frameworks!
    target "Cocoapod_03" do
    pod "AFNetworking", "3.1.0"
    end
    pod 'MJRefresh', '~> 3.1.0’  (先 vim Podfile 然后直接输入此行再 pod install 即可




    0 0
    原创粉丝点击