1、apt-get安装
可以使用apt-cache查询功能,找到对应的可用的ruby版本。
$ sudo apt-cache search ruby
#这个结果很长,我只截取最后与ruby有关的部分
ruby1.8 - Interpreter of object-oriented scripting language Ruby 1.8
ruby1.8-dev - Header files for compiling extension modules for the Ruby 1.8
ruby1.8-examples - Examples for Ruby 1.8
rubygems - package management framework for Ruby libraries/applications
rubygems1.8 - Transitional package for rubygems
rubygems-doc - Transitional package for rubygems
ruby1.9.1-full - Ruby 1.9.1 full installation
ruby1.8-full - Ruby 1.8 full installation
ruby-switch - switch between different Ruby interpreters
ruby2.1 - Interpreter of object-oriented scripting language Ruby
libruby2.1 - Libraries necessary to run Ruby 2.1
ruby2.1-dev - Header files for compiling extension modules for the Ruby 2.1
ruby2.1-tcltk - Ruby/Tk for Ruby 2.1
ruby2.1-doc - Documentation for Ruby 2.1
ruby2.2 - Interpreter of object-oriented scripting language Ruby
libruby2.2 - Libraries necessary to run Ruby 2.2
ruby2.2-dev - Header files for compiling extension modules for the Ruby 2.2
ruby2.2-tcltk - Ruby/Tk for Ruby 2.2
ruby2.2-doc - Documentation for Ruby 2.2
ruby2.3 - Interpreter of object-oriented scripting language Ruby
ruby2.3-doc - Documentation for Ruby 2.3
libruby2.3 - Libraries necessary to run Ruby 2.3
ruby2.3-dev - Header files for compiling extension modules for the Ruby 2.3
ruby2.3-tcltk - Ruby/Tk for Ruby 2.3
libruby2.4 - Libraries necessary to run Ruby 2.4
ruby2.4-dev - Header files for compiling extension modules for the Ruby 2.4
ruby2.4 - Interpreter of object-oriented scripting language Ruby
ruby2.4-doc - Documentation for Ruby 2.4
可以看到官方目前支持较多版本,
安装样例
sudo apt-get install ruby #自动安装最新版本
sudo apt-get install ruby2.0
无法指定子版本,只能用repo已有的版本。
2、使用brightbox ppa仓库安装
这是一个repo方案,已经更新到2.4版本,参考:https://www.brightbox.com/docs/ruby/ubuntu/
If you’re using Ubuntu 14.04 (Trusty) or newer then you can add the package repository like this
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update
$ sudo apt-get install ruby1.9.3 ruby1.9.3-dev
无法指定子版本,只能用repo已有的版本。
3、利用rvm安装
$ curl -L get.rvm.io | bash -s stable
$ source ~/.bashrc
$ source ~/.bash_profile
$ source ~/.profile
$ rvm -v
$ rvm list known
$ rvm install 2.2
$ ruby -v
ruby 2.2.6p396 (2016-11-15 revision 56800) [x86_64-linux]
如果想在Ubuntu上安装多个Ruby版本,那么可以使用下面的命令来指定使用rvm作为默认的Ruby版本管理。
rvm use ruby 1.9.3 --default
rvm use ruby 1.9.3-p551 --default #制定子版本
可以指定子版本,比如 rvm install 1.9.3-p551
附rvm list known结果参考。
$ rvm list known
Warning, new version of rvm available '1.29.2', you are using older version '1.29.1'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
# 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[.6]
[ruby-]2.3[.3]
[ruby-]2.4[.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[.26]
jruby[-9.1.7.0]
jruby-head
# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx[-3.71]
rbx-head
# Opal
opal
# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1[.2.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
4、编译安装
参考前一篇文章:ubuntu编译安装ruby1.9.3,从p551降级到p484(http://www.linuxdiyf.com/linux/32141.html)