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$ 




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章