RVM Ruby 管理工具

版权声明:本文为作者原创,欢迎各位转载,如需查看更多文章,请移步至本人博客园文章,地址: http://www.cnblogs.com/QianChia/。但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。 https://blog.csdn.net/QianChia123/article/details/87863059

1、RVM 简介

1.1 Ruby 简介

  • Ruby 是一种面向对象的脚本语言,简单易用,功能强大。能跨平台和可移植性好等等。其实就是种脚本语言。

  • Ruby 的软件源使用的是亚马逊的云服务,国内网络环境下载时可能会出现各种不稳定和超时,所以自带的需要翻墙。

    • 可以将官方 ruby 源替换成国内淘宝 ruby:https://ruby.taobao.org/

    • 或者是 China ruby 源:https://gems.ruby-china.org/

    • 据消息了解,2016.06 淘宝源暂停维护了,建议使用 China ruby 源。

1.2 Rvm 简介

  • Rvm 全称 Ruby Version Manager,是安装和管理 ruby 的一种工具,包括 Ruby 的版本管理和 Gem 库管理(gemset)。

    • RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

2、RVM 环境安装

2.1 检查是否存在 rvm 环境

  • 在终端输入以下指令。

    # 查看 rvm 版本
    $ rvm -v
    
    • 输出结果,不存在 rvm 环境

      -bash: rvm: command not found
      
    • 输出结果,存在 rvm 环境

      rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
      

2.2 安装配置 rvm 环境

  • 如果不存在 rvm 环境,在终端输入以下指令安装。

    # 安装 rvm
       curl -L get.rvm.io | bash -s stable
    
    • curl 是利用 URL 语法在命令行方式下工作的开源文件传输工具。它被广泛应用在 Unix、多种 Linux 发行版中,并且有 DOS 和 Win32、Win64 下的移植版本。

      扫描二维码关注公众号,回复: 5497938 查看本文章
    • 终端输出

        % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                           Dload  Upload   Total   Spent    Left  Speed
      100   194  100   194    0     0    203      0 --:--:-- --:--:-- --:--:--   203
      100 24090  100 24090    0     0  11046      0  0:00:02  0:00:02 --:--:-- 34864
      Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
      Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
      Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc',
      but no GPG software exists to validate it, skipping.
      
      Installing RVM to /Users/haiqianj/.rvm/
          Adding rvm PATH line to /Users/haiqianj/.profile /Users/QianChia/.mkshrc /Users/haiqianj/.bashrc /Users/QianChia/.zshrc.
          Adding rvm loading line to /Users/QianChia/.profile /Users/QianChia/.bash_profile /Users/haiqianj/.zlogin.
      Installation of RVM in /Users/haiqianj/.rvm/ is almost complete:
      
        * To start using RVM you need to run `source /Users/QianChia/.rvm/scripts/rvm`
          in all your open shell windows, in rare cases you need to reopen all shell windows.
      
        * WARNING: '~/.profile' file found. To load it into your shell, add the following line to '/Users/QianChia/.bash_profile':
      
            source ~/.profile
      
  • 继续在终端输入以下指令,配置 rvm 环境。

    # 配置 rvm 环境
    $ source ~/.bashrc
    $ source ~/.bash_profile
    
    • 完成后,再次输入 rvm -v 指令即可看到已成功安装。

3、Ruby 检查更新

3.1 检查 ruby 版本环境

  • 在终端输入以下指令。

    # 查看 ruby 版本
    $ ruby -v
    
    • 输出结果

      ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
      

3.2 更新 ruby 版本环境

  • 在终端输入以下指令。

    # 查询已知的 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[.7]
      [ruby-]2.3[.4]
      [ruby-]2.4[.1]
      ruby-head
      ...
      
  • 在终端输入以下指令,更新 ruby 版本环境。

    # 指定 ruby 版本进行更新( 此处按照 ruby 2.4.1 版本进行更新 )
    $ rvm install 2.4.1      
    
    • 等待一段时间后,输出以下结果,更新完成。

      Searching for binary rubies, this might take some time.
      No binary rubies available for: osx/10.13/x86_64/ruby-2.4.1.
      Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
      Checking requirements for osx.
      Certificates bundle '/usr/local/etc/[email protected]/cert.pem' is already up to date.
      Requirements installation successful.
      Installing Ruby from source to: /Users/QianChia/.rvm/rubies/ruby-2.4.1, this may take a while depending on your cpu(s)...
      ruby-2.4.1 - #downloading ruby-2.4.1, this may take a while depending on your connection...
      ** Resuming transfer from byte position 1048576
        % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
      100 10.9M  100 10.9M    0     0  43161      0  0:04:26  0:04:26 --:--:-- 37120
      ruby-2.4.1 - #extracting ruby-2.4.1 to /Users/QianChia/.rvm/src/ruby-2.4.1....
      ruby-2.4.1 - #applying patch /Users/QianChia/.rvm/patches/ruby/2.4.1/random_c_using_NR_prefix.patch.
      ruby-2.4.1 - #configuring..................................................................
      ruby-2.4.1 - #post-configuration.
      ruby-2.4.1 - #compiling..............................................................
      ruby-2.4.1 - #installing.......
      ruby-2.4.1 - #making binaries executable..
      

3.3 检查 rubygems 版本环境

  • 在终端输入以下指令。

    # 查看 rubygems 版本
    $ gem -v
    
    • 输出结果

      2.5.2
      

3.4 更新 rubygems 版本环境

  • 在终端输入以下指令。

    # 更新 rubygems 版本
    $ sudo gem update --system
    
    • 等待一段时间后,输出以下结果,更新完成。

      Updating rubygems-update
      Fetching: rubygems-update-2.6.14.gem (100%)
      Successfully installed rubygems-update-2.6.14
      Parsing documentation for rubygems-update-2.6.14
      
      • 实际打印可能与此不同,但是成功了就会显示 Successfully。
      Latest version currently installed. Aborting.
      
      • 此种提示,表示已经是最新的 rubygems 环境。

3.5 检查更新 ruby 源

  • Ruby 的软件源使用的是亚马逊的云服务,国内网络环境下载时可能会出现各种不稳定和超时,所以自带的需要翻墙。由于 2016.06 淘宝源暂停维护了,建议使用 China ruby 源。

    • 官方 ruby 源:https://rubygems.org/
    • 淘宝 ruby 源:https://ruby.taobao.org/
    • China ruby 源:https://gems.ruby-china.org/
  • 在终端输入以下指令,检查 ruby 源。

    # 检查 ruby 源
    $ gem sources -l
    
    • 输出

      *** CURRENT SOURCES ***
      
      https://rubygems.org/
      
  • 如果使用的是官方 ruby 源,继续输入以下指令删除ruby 源。

    # 删除 ruby 源
    $ sudo gem sources --remove https://rubygems.org/
    
    • 移除结果

      https://rubygems.org/ removed from sources
      
  • 替换添加国内镜像源 ruby-china 源

    # 添加 ruby 源
    $ sudo gem sources --add https://gems.ruby-china.org/
    
    • 替换结果

      https://gems.ruby-china.org added to sources
      
  • 再次检查此时的 ruby 源,已经变成了 ruby-china 源。

猜你喜欢

转载自blog.csdn.net/QianChia123/article/details/87863059
rvm
今日推荐