RVM 是一个命令行工具,能够提供一个便捷的多版本 Ruby 环境的管理和切换。git
https://rvm.io/github
若是你打算学习 Ruby / Rails, RVM 是必不可少的工具之一。web
$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB $ \curl -sSL https://get.rvm.io | bash -s stable $ source ~/.bashrc $ source ~/.bash_profile
修改 RVM 的 Ruby 安装源到 Ruby China 的 Ruby 镜像服务器,这样能提升安装速度centos
echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > /usr/local/rvm/user/db
列出已知的 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[.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
安装一个 Ruby 版本bash
#rvm install 2.6.3 Searching for binary rubies, this might take some time. No binary rubies available for: centos/7/x86_64/ruby-2.6.3. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for centos. Requirements installation successful. Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.6.3, this may take a while depending on your cpu(s)... ruby-2.6.3 - #downloading ruby-2.6.3, this may take a while depending on your connection... ** Resuming transfer from byte position 4009984 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 10.0M 100 10.0M 0 0 8270k 0 0:00:01 0:00:01 --:--:-- 8275k ruby-2.6.3 - #extracting ruby-2.6.3 to /usr/local/rvm/src/ruby-2.6.3..... ruby-2.6.3 - #configuring...................................................................... ruby-2.6.3 - #post-configuration.. ruby-2.6.3 - #compiling............................................................................................. ruby-2.6.3 - #installing................................ ruby-2.6.3 - #making binaries executable.. ruby-2.6.3 - #downloading rubygems-3.0.6 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 866k 100 866k 0 0 5355 0 0:02:45 0:02:45 --:--:-- 10029 No checksum for downloaded archive, recording checksum in user configuration. ruby-2.6.3 - #extracting rubygems-3.0.6..... ruby-2.6.3 - #removing old rubygems........ ruby-2.6.3 - #installing rubygems-3.0.6............................................... ruby-2.6.3 - #gemset created /usr/local/rvm/gems/ruby-2.6.3@global ruby-2.6.3 - #importing gemset /usr/local/rvm/gemsets/global.gems................................................................ ruby-2.6.3 - #generating global wrappers....... ruby-2.6.3 - #gemset created /usr/local/rvm/gems/ruby-2.6.3 ruby-2.6.3 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.6.3 - #generating default wrappers....... ruby-2.6.3 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-2.6.3 - #complete Ruby was built without documentation, to build it run: rvm docs generate-ri
查看安装的ruby服务器
#rvm list =* ruby-2.6.3 [ x86_64 ] # => - current # =* - current && default # * - default