1.安装 RVM
RVM:Ruby Version Manager,Ruby版本管理器,包括Ruby的版本管理和Gem库管理(gemset)
打开控制台输入命令
curl -L get.rvm.io | bash -s stable
控制台执行命令后如下
MiaozdeMacBook-Pro:~ miaoz$ 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 43 0 0:00:04 0:00:04 --:--:-- 43
100 24090 100 24090 0 0 3928 0 0:00:06 0:00:06 --:--:-- 27406
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/miaoz/.rvm/
Adding rvm PATH line to /Users/miaoz/.profile /Users/miaoz/.mkshrc /Users/miaoz/.bashrc /Users/miaoz/.zshrc.
Adding rvm loading line to /Users/miaoz/.profile /Users/miaoz/.bash_profile /Users/miaoz/.zlogin.
Installation of RVM in /Users/miaoz/.rvm/ is almost complete:
* To start using RVM you need to run `source /Users/miaoz/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
下载完成后我们执行下上边提示的命令
source /Users/miaoz/.rvm/scripts/rvm
执行完后我们使用rvm -v 验证下是否成功。
2.使用rvm升级ruby
#查看当前ruby版本
$ ruby -v
#列出已知的ruby版本
$ rvm list known
#安装ruby 2.4.1
$ rvm install 2.4.1
MiaozdeMacBook-Pro:~ miaoz$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
MiaozdeMacBook-Pro:~ miaoz$ 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
# 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.13.0]
jruby-head
# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.84]
rbx-head
# 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[-head]
# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]
# Topaz
topaz
# MagLev
maglev[-head]
maglev-1.0.0
# 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
rvm install 2.4.1