UI基础Mac工具整理iOS Developer

iOS - rvm、Ruby环境CocoaPods安装使用及相

2017-05-29  本文已影响1132人  麦穗0615

前言:

CocoaPods 作为目前库依赖管理的工具,是非常好用的一把利器。我们有了它,再也无需拖 第三方库以及第三方库所依赖的framework 仅仅只需要通过终端,输入一些指令即可完成这些操作;而且涉及到第三方库的更新升级也可以通过 CocoaPods 进行手动管理更新。

一、基本知识简介

  • 1、官网及相关链接
- **Rvm 官网** : [https://www.rvm.io/](https://www.rvm.io/)

Ruby 官网https://rubygems.org/
CocoaPods 官网https://cocoapods.org/
Rvm 安装指南:https://rvm.io/rvm/install
Homebrew 官网:http://brew.sh/index_zh-cn.html
ruby 镜像 - taobao:https://ruby.taobao.org/
ruby 镜像 - china:https://gems.ruby-china.org/

二、CocoaPods 安装使用

如果没有意外情况,按照下面走就没问题了

     `输出结果:( 存在 rvm 环境)`
      muxuguixiandeMacBook-Pro:~ jijiucheng$ rvm -v
      rvm 1.29.1 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

     `输出结果:(不存在 rvm 环境)`
      muxuguixiandeMacBook-Pro:~ jijiucheng$ rvm -v
      -bash: rvm: command not found

   ** 情况一:如果不存在 rvm 环境,先安装  配置 rvm 环境**;
      ① 期间可能会问你 `sudo管理员` 密码,以及自动通过 `homebrew` 安装依赖包;
      等待一段时间后就可以成功安装好 `rvm`。

     $ curl -L https://get.rvm.io | bash -s stable

      输出结果:(下载安装)(显示的 `` 代表一行空格)
      muxuguixiandeMacBook-Pro:~ jijiucheng$ curl -L https://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     93      0  0:00:01  0:00:01 --:--:--    93
      100 22865  100 22865    0     0   8964      0  0:00:02  0:00:02 --:--:--  710k
      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.
        ``
      `Installing RVM to /Users/smalllufeinj/.rvm/`
        Adding rvm PATH line to /Users/smalllufeinj/.profile   
        /Users/smalllufeinj/.mkshrc /Users/smalllufeinj/.bashrc   
        /Users/smalllufeinj/.zshrc.
        Adding rvm loading line to /Users/smalllufeinj/.profile     
        /Users/smalllufeinj/.bash_profile /Users/smalllufeinj/.zlogin.
       `Installation of RVM in /Users/smalllufeinj/.rvm/ is almost complete:`
        ``
       .* To start using RVM you need to run `source     
        /Users/smalllufeinj/.rvm/scripts/rvm`
        in all your open shell windows, in rare cases you need to reopen all shell windows.
        ``
        # muxuguixian,
        #
        #   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
下载安装 rvm 环境.
    ② 然后,载入 RVM 环境(新开 Termal 就不用这么做了,会自动重新载入的)。

    $ source ~/.rvm/scripts/rvm

    输出结果:(^_^)(什么都没有输出)
    muxuguixiandeMacBook-Pro:~ jijiucheng$ source ~/.rvm/scripts/rvm

    ③ 再次检查 rvm 是否安装正确。

    $ rvm -v

     `输出结果:( 存在 rvm 环境)`
      muxuguixiandeMacBook-Pro:~ jijiucheng$ rvm -v
      rvm 1.29.0 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>,     
      Michal Papis <mpapis@gmail.com> [https://rvm.io/]

情况二:如果存在 rvm 环境,用 rvm 安装 ruby 环境;

查询已知的 ruby 环境

② 指定 ruby 版本进行更新( 此处按照 ruby 2.4.0 版本进行更新 )。

    $ rvm install 2.4.0

     输出结果:( 此处因为终端输出的字符过多,所以此处用截图方式 )

![指定 ruby 版本进行更新](http:https://img.haomeiwen.com/i2156697/6d0fd02a9e44853b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

    ③ 第二步需要一段时间等待,完成后此时 rvm 环境就配置好了;Ruby Gems 就安装好了。

    ④ 补充相关指令:
          查询已安装的 ruby:
                           $ rvm list
          卸载一个已安装版本:
                            $ rvm remove 1.9.2
          $ sudo gem -v

          检查结果:( 默认情况下版本应该较低,建议升级到 )
          muxuguixiandeMacBook-Pro:local jijiucheng$ gem -v
          2.5.1

    **更新 gem ruby 版本号:**
          $ gem update --system

          更新成功:( 实际打印可能与此不同,但是成功了就会显示 Successfully )
          muxuguixiandeMacBook-Pro:local jijiucheng$ gem update --system
          Updating rubygems-update
          Fetching: rubygems-update-2.6.7.gem (100%)
          Successfully installed rubygems-update-2.6.7

          此种提示:( 表示已经是最新的 gem ruby 环境 )
          muxuguixiandeMacBook-Pro:~ jijiucheng$ gem update --system
          Latest version currently installed. Aborting.

检查 ruby 源:

          $ gem sources -l

          检查结果:( 如果电脑没安装过 CocoaPods,此时应该是默认 ruby 源 )
          muxuguixiandeMacBook-Pro:~ jijiucheng$ gem sources -l
          *** CURRENT SOURCES ***
          https://rubygems.org/

移除 ruby 源:
$ gem sources --remove https://rubygems.org/

           移除结果:
            muxuguixiandeMacBook-Pro:local jijiucheng$ gem sources --remove https://rubygems.org/
            https://rubygems.org/ removed from sources

替换添加国内镜像源** ruby-china** 源,因为上面已经提到国内镜像源 taobao 源 已经停止维护了,所以此处替换的是 ruby-china 源,且尽量确保只有一个 ruby-china 源。
也可以,可以将 官方 ruby 源 替换成国内 淘宝 ruby(https://ruby.taobao.org/

      $ gem sources --add https://gems.ruby-china.org

      替换结果:
      muxuguixiandeMacBook-Pro:local jijiucheng$ gem sources --add  https://gems.ruby-china.org
      https://gems.ruby-china.org added to sources

      再次检查此时的 ruby 源:( 已经变成了 ruby-china 源 )
      muxuguixiandeMacBook-Pro:local jijiucheng$ gem sources -l
      *** CURRENT SOURCES ***
      https://gems.ruby-china.org
安装 CocoaPods

iOS11.2
----> 指令:
----> $ sudo gem install cocoapods
----> 需要密码

  ![$ sudo gem install cocoapods 测试结果](http:https://img.haomeiwen.com/i2156697/594ca477ffb93d88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
三、CocoaPods 安装过程中报错问题解决

说明:此部分所列举的问题均是在执行相关指令时出现的报错

1、Rvm 环境搭建
报错一:
  ① Error running 'requirements_osx_brew_update_system ruby-2.3.0',   
    showing last 15 lines of /Users/jijiucheng/.rvm/log/1475769205_ruby-
    2.3.0/update_system.log
  ② curl: (35) Server aborted the SSL handshake

① 报错指令:
$ rvm install 2.3.0

 *② 报错信息:*
    Error running 'requirements_osx_brew_update_system ruby-
    2.3.0',showing last 15 lines of /Users/jijiucheng/.rvm/log/1475769205_ruby-
    2.3.0/update_system.log............Requirements installation failed with status: 1.
    curl: (35) Server aborted the SSL handshake
报错信息 1.png 报错信息 2.png

③ 报错原因:网络问题,因为需要翻墙,所以网络不稳定;建议选择 VPN,保证线路的稳定性。

④ 解决方案( 指令一行一行输入 ):
$ cd /usr/local

    $ git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

    $ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bashrc
解决方案 .png

⑤ 方案链接:方案解决链接 -- https://segmentfault.com/q/1010000004276750

报错二:
报错信息 .png

③ 报错原因:缺少 Xcode 工具,xcode command line

④ 解决方案:
$ xcode-select --install

解决方案 .png

*⑤ 方案链接:
方案解决链接 1 - http://stackoverflow.com/questions/35228481/error-running-rvm-make-install
方案解决链接 2 - http://www.th7.cn/Program/Ruby/201609/966343.shtml

报错三:

解决方案 .png

2、CocoaPods 安装及使用报错

报错一

解决方案

报错二

**更新cocoapod的时候会出现 下面错误

Performing a deep fetch of the master specs repo to improve future performance**

四、资料补充

1、指令补全

参考文章:

01:【iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决(2016.12.15 更新)
02: iOS - CocoaPods版本升级那些坑
03:gem源替换成淘宝的源
04 - Rvm、Ruby及Cocoapods安装
05 - RVM 和 Ruby的安装
06 - iOS的库依赖管理工具CocoaPods
07 - CocoaPods的安装以及遇到的坑
08 - ios开发怎样卸载已经安装的cocoapod
09 - 配置CocoaPods前 - 本地安装好Ruby环境
10 - iOS 学习笔记二【cocopods安装使用和安装过程中遇到的问题及解决办法】【20160725更新】
11 - ruby学习及编译ruby缺少openssl问题解决

问题解决
01 - 解决升级EI Capiton CocoaPods "pod: command not found"
02 - curl: (35) Server aborted the SSL handshake
03 - 第一种 - Error running '__rvm_make -j 1'
04 - 第二种 - Error running '__rvm_make -j 1'
05 - [!] Unable to add a source with url "xxxxxxxxxxxxx"
06 - Error running 'requirements_osx_brew_update_system ruby-2.0.0-p643'
07 - 关于安装cocoapods遇到的一些坑(ERROR: Error installing cocoapods: activesupport requires Ruby version >= 2.2)
08 - Homebrew install: Failed during: git fetch origin master:refs/remotes/origin/master -n --depth=1
09 - Pod /usr/bin/git clone https://github.com/CocoaPods/Specs.git master
10pod install -bash: pod: command not found

声明:

本文根据【iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决(2016.12.15 更新)进行的重新排班,和实际操作。相当于转载学习,而后,又添加了点扩充,用于自己长期学习资料留存。如果上面所有参考文章有侵权现象,请联系,删除。谢谢!

上一篇 下一篇

猜你喜欢

热点阅读