在mac 10.12上安装Cocoapods

一、检测RVM是否安装

  使用命令:$rvm -v

  结果:rvm 1.27.0 (latest) by Wayne E. Seguin , Michal Papis [https://rvm.io/]说明你应经安装RVM了,否者就要安装了:

$ curl -L get.rvm.io | bash -s stable
//需要等一会
source ~/.bashrc
source ~/.bash_profile
rvm -v ,如果能显示版本则安装成功
二、检测Ruby是否安装
这里不只是检测Ruby安装的问题,还要看Ruby的版本是否大于2.2.2,不然会报错:Error installing pods: activesupport requires Ruby version >= 2.2.2。
输入命令$ruby -v ,出现版本信息:ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
或者使用命令:$rvm list 输出信息为:rvm rubies

 ruby-2.0.0-p648 [ x86_64 ]

ruby-2.3.0 [ x86_64 ]

=* ruby-2.3.1 [ x86_64 ]

# => - current

# =* - current && default

#  * - default
如果低于2.2.2则升级版本:
$rvm list known //列出ruby可安装的版本信息
$rvm install 2.3.1 //安装一个ruby版本 rvm 2.3.1 --default //设置ruby2.3.1为系统默认版本
可能会碰到:

  Error running 'requirements_osx_brew_update_system ruby-2.3.1',

  showing last 15 lines of /Users/max-pc/.rvm/log/1479699089_ruby-2.3.1/update_system.log

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

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

这是提示我们Brew 需要更新了

三、更新brew  update

Brew是OS X上类似apt-get以及yum的一个软件包管理器,它依托于Github,这个具体是安装还是更细我当时怎么整的也忘了,就是要用新的,卸载重新安装,我感觉比较好。

但是当升级完Brew之后,可能会出现

Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mach (LoadError)

from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `'

from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /usr/local/Library/Homebrew/global.rb:3:in `'

from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /usr/local/Library/brew.rb:15:in `

'

这个问题我在知乎(知乎地址:https://www.zhihu.com/question/41371402)上找到的解决办法是卸载,重新安装:

  卸载:ruby -e "$(curl -fsSL )"

  重新安装:/usr/bin/ruby -e "$(curl -fsSL )"

四、换源

  我们需要来修改源(由于国内被墙),所以腰包源切换至ruby-china在终端执行以下命令,以前使用的大部分命令都是下面的情况:

        sudo gem update --system

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

        gem sources -a https://ruby.taobao.org/       //这个现在是个大坑啊,会报错:

              Error fetching https://ruby.taobao.org/:

              Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://ruby.taobao.org/specs.4.8.gz)

这是因为淘宝的镜像已经不再维护了,目前是ruby china社区在维护,所以,你可以执行以下命令来完成换源:

        sudo gem update --system

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

        gem sources --remove https://ruby.taobao.org/      //已经安装了淘宝镜像的需要这一步

        gem sources -a https://gems.ruby-china.org/

   使用命令  gem sources - l 来验证你的ruby镜像是并且仅是ruby-china,如果出现以下文字表名你的命令是成功的:

        *** CURRENT SOURCES ***

        https://gems.ruby-china.org/

五、安装cocoapods
执行命令:
$sudo gem install -n/usr/local/bin cocoapods
安装好之后使用pod,会出现

    Setting up CocoaPods master repo

这个就不要急了,你只需要等等吧,这说明cocoapods在将他的信息下载到~/.cocoapods里,cd  到该目录里,用du -sh *命令来查看文件大小

到出现下面的信息,说明你的cocoapods已经安装完毕,可以使用了:

CocoaPods 1.2.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 https://github.com/CocoaPods/CocoaPods/releases/tag/1.2.0.beta.1

Setup completed






你可能感兴趣的:(ios开发)