美文网首页
Homebrew 、Ruby、CocoaPods 安装

Homebrew 、Ruby、CocoaPods 安装

作者: 那是一阵清风_徐来 | 来源:发表于2018-11-28 10:47 被阅读927次
    步骤
    • 1、输入安装rvm命令
    $ curl -L https://get.rvm.io | bash -s stable
    
    期间可能会问你sudo管理员密码,以及自动通过homebrew安装依赖包,等待一段时间后就可以成功安装好 RVM。
    

    输入上述命令以后,会在终端打印如下数据:

    $ curl -L get.rvm.io | bash -s stable
    
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   194  100   194    0     0     30      0  0:00:06  0:00:06 --:--:--    53
    100 24361  100 24361    0     0   3129      0  0:00:07  0:00:07 --:--:-- 36916
    Downloading https://github.com/rvm/rvm/archive/1.29.4.tar.gz
    curl: (56) SSLRead() return error -36
    
    Could not download 'https://github.com/rvm/rvm/archive/1.29.4.tar.gz'.
      curl returned status '56'.
    
    Downloading https://bitbucket.org/mpapis/rvm/get/1.29.4.tar.gz
    Downloading https://bitbucket.org/mpapis/rvm/downloads/1.29.4.tar.gz.asc
    Found PGP signature at: 'https://bitbucket.org/mpapis/rvm/downloads/1.29.4.tar.gz.asc',
    but no GPG software exists to validate it, skipping.
    Upgrading the RVM installation in /Users/majq/.rvm/
        RVM PATH line found in /Users/majq/.mkshrc /Users/majq/.profile /Users/majq/.bashrc /Users/majq/.zshrc.
        RVM sourcing line found in /Users/majq/.profile /Users/majq/.bash_profile /Users/majq/.zlogin.
    Upgrade of RVM in /Users/majq/.rvm/ is complete.
      * No new notes to display.
    
    
    2、装载rvm
    $  source ~/.rvm/scripts/rvm
    
    3、检查一下是否安装正确
    $ rvm -v  
    
    打印如下:
    rvm 1.29.4 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
    
    更多操作
    • 列出已知ruby的版本

      $  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[.10]
      [ruby-]2.2[.10]
      [ruby-]2.3[.7]
      [ruby-]2.4[.4]
      [ruby-]2.5[.1]
      [ruby-]2.6[.0-preview2]
      ruby-head
      ....(还有很多我没录入)
      
    • 使用RVM升级Ruby

    • 查看ruby版本

      $  ruby -v
      ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
      
      
    • 安装ruby

      $  rvm install 版本号
      
      比如:rvm install 2.5.1
      
    • 查询已经安装的ruby

      $ rvm list
      
    • *卸载一个已安装版本 *

      $ rvm remove 1.9.2
      
    • 查看gem版本

      $  gem -v
      YAML safe loading is not available. Please upgrade psych to a version that supports safe loading (>= 2.0).【这个应该是需要跟新 ruby,需要版本> 2.0,,具体方法参考上述描述】
      2.7.7
      
      

    如果安装ruby 出现问题,可以去检查一下是否安装Homebrew

    • 安装Homebrew

    可以去官网查看命令

    $  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    此过程需要输入密码,详情打印如下:
    ==> This script will install:
    /usr/local/bin/brew
    /usr/local/share/doc/homebrew
    /usr/local/share/man/man1/brew.1
    /usr/local/share/zsh/site-functions/_brew
    /usr/local/etc/bash_completion.d/brew
    /usr/local/Homebrew
    ==> The Xcode Command Line Tools will be installed.
    
    Press RETURN to continue or any other key to abort
    ==> Searching online for the Command Line Tools
    ==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
    Password:
    ==> Installing Command Line Tools (macOS Mojave version 10.14) for Xcode-10.1
    ==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ (macOS\ Mojave\ version\ 10.14)\ for\ Xcode-10.1
    Software Update Tool
    
    
    Downloading Command Line Tools (macOS Mojave version 10.14) for Xcode
    Downloaded Command Line Tools (macOS Mojave version 10.14) for Xcode
    Installing Command Line Tools (macOS Mojave version 10.14) for Xcode
    Done with Command Line Tools (macOS Mojave version 10.14) for Xcode
    Done.
    ==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
    ==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
    ==> Downloading and installing Homebrew...
    remote: Enumerating objects: 6, done.
    remote: Counting objects: 100% (6/6), done.
    remote: Compressing objects: 100% (6/6), done.
    Receiving objects:   3% (4284/114968), 1.68 MiB | 59.00 KiB/s   s  
    ...
    
    • Homebrew 更多操作

    • 检查版本

      $  brew -v
      
    gem 相关操作
    • 查看gem 源
    $  gem sources -l
    
    打印如下:
    *** CURRENT SOURCES ***
    https://rubygems.org/
    
    • 更换gem 源
    $  gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
    
    或者 拆分成如下3步:
    第一步:移除现有的Ruby镜像
    $  gem sources --remove https://rubygems.org/
    
    第二步:再次查看现有的Ruby镜像
    $  gem sources -l
    
    第三步:添加国内最新镜像源
    $  gem sources -a https://gems.ruby-china.com/
    
    打印如下:
    https://gems.ruby-china.com/ added to sources
    https://rubygems.org/ removed from sources
    
    安装cocoapods
    $   sudo gem install -n /usr/local/bin cocoapods
    
    过程需要输入密码,打印详情如下:
    Password:
    Fetching: concurrent-ruby-1.1.3.gem (100%)
    Successfully installed concurrent-ruby-1.1.3
    Fetching: i18n-0.9.5.gem (100%)
    Successfully installed i18n-0.9.5
    Fetching: thread_safe-0.3.6.gem (100%)
    Successfully installed thread_safe-0.3.6
    Fetching: tzinfo-1.2.5.gem (100%)
    Successfully installed tzinfo-1.2.5
    Fetching: activesupport-4.2.11.gem (100%)
    Successfully installed activesupport-4.2.11
    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.5.3.gem (100%)
    Successfully installed cocoapods-core-1.5.3
    Fetching: claide-1.0.2.gem (100%)
    Successfully installed claide-1.0.2
    Fetching: cocoapods-deintegrate-1.0.2.gem (100%)
    Successfully installed cocoapods-deintegrate-1.0.2
    Fetching: cocoapods-downloader-1.2.2.gem (100%)
    Successfully installed cocoapods-downloader-1.2.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.11.0.gem (100%)
    Successfully installed netrc-0.11.0
    Fetching: cocoapods-trunk-1.3.1.gem (100%)
    Successfully installed cocoapods-trunk-1.3.1
    Fetching: cocoapods-try-1.1.0.gem (100%)
    Successfully installed cocoapods-try-1.1.0
    Fetching: molinillo-0.6.6.gem (100%)
    Successfully installed molinillo-0.6.6
    Fetching: atomos-0.1.3.gem (100%)
    Successfully installed atomos-0.1.3
    Fetching: CFPropertyList-3.0.0.gem (100%)
    Successfully installed CFPropertyList-3.0.0
    Fetching: colored2-3.1.2.gem (100%)
    Successfully installed colored2-3.1.2
    Fetching: nanaimo-0.2.6.gem (100%)
    Successfully installed nanaimo-0.2.6
    Fetching: xcodeproj-1.7.0.gem (100%)
    Successfully installed xcodeproj-1.7.0
    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.1.3.gem (100%)
    Successfully installed gh_inspector-1.1.3
    Fetching: ruby-macho-1.3.1.gem (100%)
    Successfully installed ruby-macho-1.3.1
    Fetching: cocoapods-1.5.3.gem (100%)
    Successfully installed cocoapods-1.5.3
    Parsing documentation for concurrent-ruby-1.1.3
    Installing ri documentation for concurrent-ruby-1.1.3
    Parsing documentation for i18n-0.9.5
    Installing ri documentation for i18n-0.9.5
    Parsing documentation for thread_safe-0.3.6
    Installing ri documentation for thread_safe-0.3.6
    Parsing documentation for tzinfo-1.2.5
    Installing ri documentation for tzinfo-1.2.5
    Parsing documentation for activesupport-4.2.11
    Installing ri documentation for activesupport-4.2.11
    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.5.3
    Installing ri documentation for cocoapods-core-1.5.3
    Parsing documentation for claide-1.0.2
    Installing ri documentation for claide-1.0.2
    Parsing documentation for cocoapods-deintegrate-1.0.2
    Installing ri documentation for cocoapods-deintegrate-1.0.2
    Parsing documentation for cocoapods-downloader-1.2.2
    Installing ri documentation for cocoapods-downloader-1.2.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.11.0
    Installing ri documentation for netrc-0.11.0
    Parsing documentation for cocoapods-trunk-1.3.1
    Installing ri documentation for cocoapods-trunk-1.3.1
    Parsing documentation for cocoapods-try-1.1.0
    Installing ri documentation for cocoapods-try-1.1.0
    Parsing documentation for molinillo-0.6.6
    Installing ri documentation for molinillo-0.6.6
    Parsing documentation for atomos-0.1.3
    Installing ri documentation for atomos-0.1.3
    Parsing documentation for CFPropertyList-3.0.0
    Installing ri documentation for CFPropertyList-3.0.0
    Parsing documentation for colored2-3.1.2
    Installing ri documentation for colored2-3.1.2
    Parsing documentation for nanaimo-0.2.6
    Installing ri documentation for nanaimo-0.2.6
    Parsing documentation for xcodeproj-1.7.0
    Installing ri documentation for xcodeproj-1.7.0
    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.1.3
    Installing ri documentation for gh_inspector-1.1.3
    Parsing documentation for ruby-macho-1.3.1
    Installing ri documentation for ruby-macho-1.3.1
    Parsing documentation for cocoapods-1.5.3
    Installing ri documentation for cocoapods-1.5.3
    Done installing documentation for concurrent-ruby, i18n, thread_safe, tzinfo, activesupport, nap, fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 34 seconds
    28 gems installed
    
    
    • 查看版本
    $  pod --version
    
    • 再执行如下
    $  pod setup
    
    此过程需漫长等待,打印详情如下:
    Setting up CocoaPods master repo
      $ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
      Cloning into 'master'...
      remote: Enumerating objects: 436, done.        
      remote: Counting objects: 100% (436/436), done.        
      remote: Compressing objects: 100% (319/319), done.        
      Receiving objects:   7% (195802/2636757), 39.11 MiB | 60.00 KiB/s  
    ......
    
    
    

    附录:
    当执行 pod setup 时,因为下载的内容太大,时间很漫长,看起来就像卡在不动一样
    可以通过 命令行 来查看进度

    步骤如下:

    第一步:command+n 新建一个终端窗口
    第二步:$ cd ~/.cocoapods/
    第三步:$ du -sh *
    *******打印如下: 11M repos*******
    第四步:$ du -sh *
    *******打印如下: 12M repos*******
    每次输入 $ du -sh *,可以看出下载的进度

    问题解决方案:
    • 如果安装一直无法解决,那么请输入命令$ brew doctor 来查看问题的解决方法,会提示哪些地方出现问题,然后意义解决
    • 1、pod install 失败
      /Library/Ruby/Site/2.0.0/rubygems.rb:250:in 'find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException) from /Library/Ruby/Site/2.0.0/rubygems.rb:278:in 'activate_bin_path' from /usr/local/bin/pod:22:in '<main>''
    这是由于 ruby 环境太低导致的
    解决办法: 跟新gem
    
    $  sudo gem update --system
    或者 重新安装 cocopods
    
    
    • 2、pod setup 失败
      error: RPC failed; curl 18 transfer closed with outstanding read data remaining fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed
      原因:这个错误是因为项目太久,tag资源文件太大curl的postBuffer默认值太小,需要在终端重新配置这个值 ,git pull 时候,也可能会遇到这个问题,git 使用清查看git 常用命令
    #解决方法1:
    $  git config --global http.postBuffer 524288000
    
    # 显示当前的Git配置【查看http.postbuffer=524288000 是否是设置的值】
    $  git config --list
    
    方案一解决不了,请执行方案二
    #解决方法2:
    #上面错误有可能是os10.11+和cocoapods1.0+版本升级的安全机制更改造成的。主要出现在pod setup过程中。且该过程等待时间非常长,所以,你可以在
    $  sudo gem install -n /usr/local/bin cocoapods
    #命令后再直接执行
    $  git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
    
    上述如果还解决不了,可能是网络不好,去别人的电脑下面,去拷贝一份,直接粘贴在相同目录下,这种方法亲测可行
    

    相关文章

      网友评论

          本文标题:Homebrew 、Ruby、CocoaPods 安装

          本文链接:https://www.haomeiwen.com/subject/kvjgqqtx.html