Mac 上面使用cocoapods的一些问题

        因为项目需要,需要使用cocoapods来引入第三方编写项目,经过一上午时间终于集成好并能使用,故此总结一下本人遇到的一些坑以及解决方法跟大家分享下,因为只接触一上午,有些地方还没找到解决方法,如果方法不对的地方还请指出。

     言归正传,使用cocoapods需要使用ruby来下载,一般mac上面都会有ruby,只不过版本比较低,我们可以使用

    ruby -v

  命令来查看ruby的版本:

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15];

这里我们可以看到ruby的版本是2.0.0p648,如果想更新ruby的话,有两种方法来更新,一个是使用homebrew,另外一个是使用rvm。想知道他们两者是什么可以查看hommebrew:http://brew.sh/index_zh-cn.html,rvm:http://ruby-china.org/topics/576;.

下面为大家总结一下两者使用方法:

homebrew(因为路径问题,本人并没有使用homebrew成功安装cocoapods),命令行:

brew install ruby        使用brew安装或者更新ruby。
brew info ruby      看一下ruby有几个版本
brew switch ruby    切换ruby到指定版本,例如:brew switch ruby 2.2.3
brew uninstall ruby   卸载ruby
卸载brew:
cd `brew --prefix`
rm
-rf Cellar
brew prune
rm `git ls
-files`
rm
-r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm
-rf .git
rm
-rf ~/Library/Caches/Homebrew

    当安装上brew, 运行brew install ruby指令安装更新ruby,期间可能输入电脑密码,输上之后就可以下载下来了,然后用ruby -v指令会打印还是2.0.0,这是因为mac默认获取的ruby路径并不是brew下载安装ruby的路径,

可以这样看一下;

type ruby

打印的是

/usr/bin/ruby
这是mac系统默认给我们安装的2.0.0版本,但是 用brew install ruby 会安装在 /usr/local/Cellar/ruby/2.2.3/bin/ruby 路径下,

这就是为何当我们使用brew install ruby的时候

ERROR:  Error installing cocoapods:

activesupport requires Ruby version >= 2.2.2.

会有这样的错误。

ram:使用ram的时候,我们可以rvm -v查看电脑rvm版本,

rvm 1.27.0 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/],如果没有的话可以重新安装一下rvm:

$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

当出现rvm 1.27的时候证明rvm是可以用的,我们可以直接使用rvm,然后直接rvm install 2.3.1_2来下载ruby 2.3.1_2,可能报错:

There was an error(6).

Checking fallback: https://ftp.ruby-lang.org/pub/ruby/./ruby-2.3.1_2.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

这是因为缺少管理员操作,下一步本人直接

sudo gem install cocoa pods    提示:25 gems installed

然后直接成功。

安装后就可以上使用cocoapods了

 1.首先先新建一个项目。在终端中进入你这个项目的所在目录(cd命令)

 比如:/Users/wzz/Desktop/myDemo/cocoaPodsDemo

 2.在终端输入:pod init

之后你会发现你这个项目的目录下多了一个Podfile文件

然后打开它进行编辑:

   pod 'SDWebImage'

   pod 'AFNetworking'等你需要的第三方框架

 3,然后再终端输入:pod install


ok  ok   ok


下面是本人操作时候的终端命令:


Last login: Thu Nov 10 12:05:16 on ttys000

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ sudo /usr/sbin/apachectl restart

Password:

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ brew install ruby

Updating Homebrew...

Warning: ruby-2.3.1_2 already installed

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ 

  [恢复于 2016年11月10日 下午1:27:58]

Last login: Thu Nov 10 13:27:45 on console

Restored session: 2016年11月10日 星期四 13时25分42秒 CST

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ brew install ruby

Updating Homebrew...

Warning: ruby-2.3.1_2 already installed

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ brew info ruby

ruby: stable 2.3.1 (bottled), devel 2.4.0-beta2, HEAD

Powerful, clean, object-oriented scripting language

https://www.ruby-lang.org/

/usr/local/Cellar/ruby/2.3.1_2 (1,261 files, 18.8M) *

  Poured from bottle on 2016-11-10 at 12:19:29

From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ruby.rb

==> Dependencies

Build: pkg-config

Required: libyaml , openssl

Recommended: readline

Optional: gdbm , gmp , libffi

==> Options

--universal

Build a universal binary

--with-doc

Install documentation

--with-gdbm

Build with gdbm support

--with-gmp

Build with gmp support

--with-libffi

Build with libffi support

--with-suffix

Suffix commands with '23'

--with-tcltk

Install with Tcl/Tk support

--without-readline

Build without readline support

--devel

Install development version 2.4.0-beta2

--HEAD

Install HEAD version

==> Caveats

Emacs Lisp files have been installed to:

  /usr/local/share/emacs/site-lisp/ruby

appledeMacBook-Pro:~ apple$ brew switch ruby 2.3.1

Error: ruby does not have a version "2.3.1" in the Cellar.

Versions available: 2.3.1_2

appledeMacBook-Pro:~ apple$ brew switch ruby 2.3.1_2

Cleaning /usr/local/Cellar/ruby/2.3.1_2

1225 links created for /usr/local/Cellar/ruby/2.3.1_2

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ type ruby

ruby is hashed (/usr/bin/ruby)

appledeMacBook-Pro:~ apple$ curl -L https://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: (6) Could not resolve host: get.rvm.io

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ rvm -v

rvm 1.27.0 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

appledeMacBook-Pro:~ apple$ rvm install 2.3.1_2

Searching for binary rubies, this might take some time.

No binary rubies available for: osx/10.11/x86_64/ruby-2.3.1_2.

Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.

Checking requirements for osx.

Installing requirements for osx.

Updating system.....

Installing required packages: libksba..

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.3.1_2, this may take a while depending on your cpu(s)...

ruby-2.3.1_2 - #downloading ruby-2.3.1_2, 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     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Transient problem: timeout Will retry in 2 seconds. 3 retries left.

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Transient problem: timeout Will retry in 2 seconds. 2 retries left.

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Transient problem: timeout Will retry in 2 seconds. 1 retries left.

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: cache.ruby-lang.org

There was an error(6).

Checking fallback: https://ftp.ruby-lang.org/pub/ruby/./ruby-2.3.1_2.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.

appledeMacBook-Pro:~ apple$ echo "export rvm_max_time_flag=20" >> ~/.rvmrc

appledeMacBook-Pro:~ apple$ 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

appledeMacBook-Pro:~ apple$ brew switch ruby 2.2[.4]

Error: ruby does not have a version "2.2[.4]" in the Cellar.

Versions available: 2.3.1_2

appledeMacBook-Pro:~ apple$ rvm -v

rvm 1.27.0 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

appledeMacBook-Pro:~ apple$ 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

appledeMacBook-Pro:~ apple$ sudo rvm install 2.0.0)

Password:

Searching for binary rubies, this might take some time.

No binary rubies available for: osx/10.11/x86_64/ruby-2.0.0).

Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.

Checking requirements for osx.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Error: Running Homebrew as root is extremely dangerous and no longer supported.

As Homebrew does not drop privileges on installation you would be giving all

build scripts full access to your system.

Installing requirements for osx.

Updating system.......

Error running 'requirements_osx_brew_update_system ruby-2.0.0)',

showing last 15 lines of /Users/apple/.rvm/log/1478758370_ruby-2.0.0)/update_system.log

    https://github.com/Homebrew/homebrew/wiki/Common-Issues

and make sure `brew update` works before continuing.'

++ rvm_pretty_print stderr

++ case "${rvm_pretty_print_flag:=auto}" in

++ case "${TERM:-dumb}" in

++ case "$1" in

++ [[ -t 2 ]]

++ return 1

++ printf %b 'Failed to update Homebrew, follow instructions here:

    https://github.com/Homebrew/homebrew/wiki/Common-Issues

and make sure `brew update` works before continuing.\n'

Failed to update Homebrew, follow instructions here:

    https://github.com/Homebrew/homebrew/wiki/Common-Issues

and make sure `brew update` works before continuing.

++ return 1

Requirements installation failed with status: 1.

/Users/apple/.rvm/bin/rvm: line 66: shell_session_update: command not found

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ ruby sudo gem install cocoapods

ruby: No such file or directory -- sudo (LoadError)

appledeMacBook-Pro:~ apple$ sudo gem install cocoapods

ERROR:  Error installing cocoapods:

activesupport requires Ruby version >= 2.2.2.

appledeMacBook-Pro:~ apple$ ruby -v

ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

appledeMacBook-Pro:~ apple$ gem sources --remove https://rubygems.org/

source https://rubygems.org/ not present in cache

appledeMacBook-Pro:~ apple$ gem sources -l

*** CURRENT SOURCES ***


https://ruby.taobao.org/

appledeMacBook-Pro:~ apple$ sudo gem install cocoapods

ERROR:  Error installing cocoapods:

activesupport requires Ruby version >= 2.2.2.

appledeMacBook-Pro:~ apple$ rvm install 2.2.2

Searching for binary rubies, this might take some time.

Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.11/x86_64/ruby-2.2.2.tar.bz2

Checking requirements for osx.

Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.

Requirements installation successful.

ruby-2.2.2 - #configure

ruby-2.2.2 - #download

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100 6854k  100 6854k    0     0  21082      0  0:05:32  0:05:32 --:--:-- 37241

ruby-2.2.2 - #validate archive

ruby-2.2.2 - #extract

ruby-2.2.2 - #validate binary

ruby-2.2.2 - #setup

ruby-2.2.2 - #gemset created /Users/apple/.rvm/gems/ruby-2.2.2@global

ruby-2.2.2 - #importing gemset /Users/apple/.rvm/gemsets/global.gems...........-

ruby-2.2.2 - #generating global wrappers........

ruby-2.2.2 - #gemset created /Users/apple/.rvm/gems/ruby-2.2.2

ruby-2.2.2 - #importing gemsetfile /Users/apple/.rvm/gemsets/default.gems evaluated to empty gem list

ruby-2.2.2 - #generating default wrappers........

Updating certificates in '/etc/openssl/cert.pem'.

mkdir: /etc/openssl: Permission denied

mkdir -p "/etc/openssl" failed, retrying with sudo

apple password required for 'mkdir -p /etc/openssl': 

and sudo mkdir worked

appledeMacBook-Pro:~ apple$ sudo gem install cocoapods

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: activesupport-4.2.7.1.gem (100%)

Successfully installed activesupport-4.2.7.1

Fetching: claide-1.0.1.gem (100%)

Successfully installed claide-1.0.1

Fetching: fuzzy_match-2.0.4.gem (100%)

Successfully installed fuzzy_match-2.0.4

Fetching: nap-1.1.0.gem (100%)

Successfully installed nap-1.1.0

Fetching: cocoapods-core-1.1.1.gem (100%)

Successfully installed cocoapods-core-1.1.1

Fetching: cocoapods-deintegrate-1.0.1.gem (100%)

Successfully installed cocoapods-deintegrate-1.0.1

Fetching: cocoapods-downloader-1.1.2.gem (100%)

Successfully installed cocoapods-downloader-1.1.2

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.1.1.gem (100%)

Successfully installed cocoapods-trunk-1.1.1

Fetching: cocoapods-try-1.1.0.gem (100%)

Successfully installed cocoapods-try-1.1.0

Fetching: colored-1.2.gem (100%)

Successfully installed colored-1.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.2.gem (100%)

Successfully installed gh_inspector-1.0.2

Fetching: molinillo-0.5.3.gem (100%)

Successfully installed molinillo-0.5.3

Fetching: CFPropertyList-2.3.3.gem (100%)

Successfully installed CFPropertyList-2.3.3

Fetching: nanaimo-0.2.2.gem (100%)

Successfully installed nanaimo-0.2.2

Fetching: xcodeproj-1.4.1.gem (100%)

Successfully installed xcodeproj-1.4.1

Fetching: cocoapods-1.1.1.gem (100%)

Successfully installed cocoapods-1.1.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 activesupport-4.2.7.1

Installing ri documentation for activesupport-4.2.7.1

Parsing documentation for claide-1.0.1

Installing ri documentation for claide-1.0.1

Parsing documentation for fuzzy_match-2.0.4

Installing ri documentation for fuzzy_match-2.0.4

Parsing documentation for nap-1.1.0

Installing ri documentation for nap-1.1.0

Parsing documentation for cocoapods-core-1.1.1

Installing ri documentation for cocoapods-core-1.1.1

Parsing documentation for cocoapods-deintegrate-1.0.1

Installing ri documentation for cocoapods-deintegrate-1.0.1

Parsing documentation for cocoapods-downloader-1.1.2

Installing ri documentation for cocoapods-downloader-1.1.2

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.1.1

Installing ri documentation for cocoapods-trunk-1.1.1

Parsing documentation for cocoapods-try-1.1.0

Installing ri documentation for cocoapods-try-1.1.0

Parsing documentation for colored-1.2

Installing ri documentation for colored-1.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.2

Installing ri documentation for gh_inspector-1.0.2

Parsing documentation for molinillo-0.5.3

Installing ri documentation for molinillo-0.5.3

Parsing documentation for CFPropertyList-2.3.3

Installing ri documentation for CFPropertyList-2.3.3

Parsing documentation for nanaimo-0.2.2

Installing ri documentation for nanaimo-0.2.2

Parsing documentation for xcodeproj-1.4.1

Installing ri documentation for xcodeproj-1.4.1

Parsing documentation for cocoapods-1.1.1

Installing ri documentation for cocoapods-1.1.1

Done installing documentation for i18n, thread_safe, tzinfo, activesupport, claide, fuzzy_match, nap, cocoapods-core, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, colored, escape, fourflusher, gh_inspector, molinillo, CFPropertyList, nanaimo, xcodeproj, cocoapods after 30 seconds

25 gems installed

appledeMacBook-Pro:~ apple$ 

appledeMacBook-Pro:~ apple$ 




猜你喜欢

转载自blog.csdn.net/ikceo1211/article/details/53115459