RVM 的安装与使用

官网:https://rvm.io/ - 中文网:https://ruby-china.org/wiki/rvm-guide

建议科学上网,若采用国内镜像源,可能由于镜像源不同步 / 不完整 / 依赖关系冲突,导致报错

  • 1、下载安装,命令如下

    1
    curl -L get.rvm.io | bash -s stable
  • 终端输出如下
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
    Dload Upload Total Spent Left Speed
    100 194 100 194 0 0 109 0 0:00:01 0:00:01 --:--:-- 109
    100 24532 100 24532 0 0 8582 0 0:00:02 0:00:02 --:--:-- 79649
    Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
    Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
    Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc',
    but no GPG software exists to validate it, skipping.
    Installing RVM to /Users/jackiequ/.rvm/
    Adding rvm PATH line to /Users/jackiequ/.profile /Users/jackiequ/.mkshrc /Users/jackiequ/.bashrc /Users/jackiequ/.zshrc.
    Adding rvm loading line to /Users/jackiequ/.profile /Users/jackiequ/.bash_profile /Users/jackiequ/.zlogin.
    Installation of RVM in /Users/jackiequ/.rvm/ is almost complete:

    * To start using RVM you need to run `source /Users/jackiequ/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
    Thanks for installing RVM 🙏
    Please consider donating to our open collective to help us maintain RVM.

    👉 Donate: https://opencollective.com/rvm/donate
  • 2、重载配置文件,命令如下

    1
    2
    source ~/.bashrc
    source ~/.bash_profile
  • 3、查看版本,命令如下

    1
    rvm -v
  • 终端输出如下
    1
    rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
  • 4、列出已知 Ruby 版本,命令如下

    1
    rvm list known
  • 终端输出如下
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    # 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[.8]
    [ruby-]2.4[.10]
    [ruby-]2.5[.8]
    [ruby-]2.6[.6]
    [ruby-]2.7[.2]
    [ruby-]3[.0.0]
    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[.27]
    jruby-9.1[.17.0]
    jruby[-9.2.14.0]
    jruby-head

    # Rubinius
    rbx-1[.4.3]
    rbx-2.3[.0]
    rbx-2.4[.1]
    rbx-2[.5.8]
    rbx-3[.107]
    rbx-4[.20]
    rbx-5[.0]
    rbx-head

    # TruffleRuby
    truffleruby[-20.3.0]

    # Opal
    opal

    # Minimalistic ruby implementation - ISO 30170:2012
    mruby-1.0.0
    mruby-1.1.0
    mruby-1.2.0
    mruby-1.3.0
    mruby-1[.4.1]
    mruby-2.0.1
    mruby-2[.1.1]
    mruby[-head]

    # Ruby Enterprise Edition
    ree-1.8.6
    ree[-1.8.7][-2012.02]

    # Topaz
    topaz

    # MagLev
    maglev-1.0.0
    maglev-1.1[RC1]
    maglev[-1.2Alpha4]
    maglev-head

    # 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
  • 5、安装指定版本 Ruby,命令如下

    1
    rvm install 3.0.0
  • 终端报错如下
    【依赖问题,需先安装 Homebrew,详见Homebrew 的安装与使用.md
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    No binary rubies available for: osx/14.4/x86_64/ruby-3.0.0.
    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 - please wait
    Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, libksba, readline, zlib, openssl@1.1 - please wait
    There were package installation errors, make sure to read the log.

    Try `brew tap --repair` and make sure `brew doctor` looks reasonable.

    Check Homebrew requirements https://docs.brew.sh/Installation
    Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config coreutils libyaml libksba readline zlib openssl@1.1',
    please read /Users/jackiequ/.rvm/log/1710891506_ruby-3.0.0/package_install_autoconf_automake_libtool_pkg-config_coreutils_libyaml_libksba_readline_zlib_openssl@1.1.log
    Requirements installation failed with status: 1.
    【网络问题 1,建议科学上网】
    1
    2
    3
    4
    5
    6
    7
    Searching for binary rubies, this might take some time.
    No binary rubies available for: osx/14.4/x86_64/ruby-3.0.0.
    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 - please wait
    Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, libksba, readline, zlib, openssl@1.1 - please wait
    【网络问题 2,建议科学上网】
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Searching for binary rubies, this might take some time.
    No binary rubies available for: osx/14.4/x86_64/ruby-3.0.0.
    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 - please wait
    Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, libksba, readline, zlib, openssl@1.1 - please wait
    There were package installation errors, make sure to read the log.

    Try `brew tap --repair` and make sure `brew doctor` looks reasonable.

    Check Homebrew requirements https://docs.brew.sh/Installation
    Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config coreutils libyaml libksba readline zlib openssl@1.1',
    please read /Users/jackiequ/.rvm/log/1710891506_ruby-3.0.0/package_install_autoconf_automake_libtool_pkg-config_coreutils_libyaml_libksba_readline_zlib_openssl@1.1.log
    Requirements installation failed with status: 1.
    【网络问题 3,建议科学上网】
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Searching for binary rubies, this might take some time.
    No binary rubies available for: osx/14.4/x86_64/ruby-3.0.0.
    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 - please wait
    Failed to update Homebrew, follow instructions at

    https://docs.brew.sh/Common-Issues

    and make sure `brew update` works before continuing.
    Error running 'requirements_osx_brew_update_system ruby-3.0.0',
    please read /Users/jackiequ/.rvm/log/1710943526_ruby-3.0.0/update_system.log
    Requirements installation failed with status: 1.
  • 终端输出如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    Searching for binary rubies, this might take some time.
    No binary rubies available for: osx/14.4/x86_64/ruby-3.0.0.
    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 - please wait
    Installing required packages: openssl@1.1 - please wait
    Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
    Requirements installation successful.
    Installing Ruby from source to: /Users/jackiequ/.rvm/rubies/ruby-3.0.0, this may take a while depending on your cpu(s)...
    ruby-3.0.0 - #downloading ruby-3.0.0, this may take a while depending on your connection...
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 18.6M 100 18.6M 0 0 69555 0 0:04:40 0:04:40 --:--:-- 77673
    ruby-3.0.0 - #extracting ruby-3.0.0 to /Users/jackiequ/.rvm/src/ruby-3.0.0 - please wait
    ruby-3.0.0 - #configuring - please wait
    ruby-3.0.0 - #post-configuration - please wait
    ruby-3.0.0 - #compiling - please wait
    ruby-3.0.0 - #installing - please wait
    ruby-3.0.0 - #making binaries executable - please wait
    Installed rubygems 3.2.3 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
    ruby-3.0.0 - #gemset created /Users/jackiequ/.rvm/gems/ruby-3.0.0@global
    ruby-3.0.0 - #importing gemset /Users/jackiequ/.rvm/gemsets/global.gems - please wait
    ruby-3.0.0 - #generating global wrappers - please wait
    ruby-3.0.0 - #gemset created /Users/jackiequ/.rvm/gems/ruby-3.0.0
    ruby-3.0.0 - #importing gemsetfile /Users/jackiequ/.rvm/gemsets/default.gems evaluated to empty gem list
    ruby-3.0.0 - #generating default wrappers - please wait
    ruby-3.0.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
    Install of ruby-3.0.0 - #complete
    Ruby was built without documentation, to build it run: rvm docs generate-ri
  • 6、列出已装 Ruby 版本,命令如下

    1
    rvm list
  • 终端输出如下
    1
    2
    3
    4
    5
    =* ruby-3.0.0 [ x86_64 ]

    # => - current
    # =* - current && default
    # * - default
  • 7、设置默认 Ruby 版本,命令如下

    1
    rvm use 3.0.0 --default
  • 终端输出如下
    1
    Using /Users/jackiequ/.rvm/gems/ruby-3.0.0
  • 8、查看 Ruby 版本,命令如下

    1
    ruby -v
  • 终端输出如下
    1
    ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin23]

仅供参考