美文网首页
Ruby 安装 for Mac(2019/9/3)

Ruby 安装 for Mac(2019/9/3)

作者: 骑马纵天下 | 来源:发表于2019-10-14 15:14 被阅读0次

    一、安装Ruby环境

    1. 在终端执行下方命令,安装RVM。

    最新版本应该是1.29.9
    $ curl -sSL https://get.rvm.io | bash -s stable
    

    2. 载入RVM环境

    $ source ~/.rvm/scripts/rvm
    

    3. 替换RVM下载Ruby源。

    首先通过gem source查看ruby源,如果是.org替换为https://gems.ruby-china.com

    leon:~ huanghaipo$ gem source
    *** CURRENT SOURCES ***
    https://gems.ruby-china.org
    #替换源
    gem source -r https://rubygems.org/
    gem source -a https://gems.ruby-china.org
    

    4. 检测是否安装正确。

    rvm -v
    

    报错,根据提示执行rvm get stable --auto-dotfiles重载。

    Warning! PATH is not properly set up, /Users/huanghaipo/.rvm/gems/ruby-2.0.0-p648/bin is not at first place.
             Usually this is caused by shell initialization files. Search for PATH=... entries.
             You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
             To fix it temporarily in this shell session run: rvm use ruby-2.0.0-p648
             To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
    rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
    
    

    正常


    RVM更新命令$ rvm get stable

    二、安装Ruby

    1. 通过Homebrew(包管理器)安装Ruby

    brew install ruby
    

    2. 通过RVM安装Ruby

    安装指定版本
    $ rvm install 版本
    安装最新版本
    $ rvm install ruby --head
    

    3. 查看可安装的Ruby版本

    $ rvm list known
    leon:~ huanghaipo$ 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[.8]
    [ruby-]2.4[.6]
    [ruby-]2.5[.5]
    [ruby-]2.6[.3]
    [ruby-]2.7[.0-preview1]
    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.7.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[.3]
    rbx-head
    
    # TruffleRuby
    truffleruby[-19.1.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[-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
    
    

    4. 设置默认版本

    $ rvm use 2.6.3 --default
    

    5. 查看安装的ruby版本

    leon:~ huanghaipo$ ruby -v
    ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
    

    三、RVM其他命令

    1. rvm信息

    $ rvm info
    

    2. 查看ruby版本

    $ rvm list known
    

    3. 查看已经安装的ruby版本

    $ rvm list
    

    4. 设置ruby默认版本

    $ rvm use 版本号 --default
    

    5. 升级

    $ rvm get head
    

    6. 移除ruby版本

    $ rvm remove 版本号
    

    相关文章

      网友评论

          本文标题:Ruby 安装 for Mac(2019/9/3)

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