Installation

macOS 10.12

First of all, you should choose homebrew or rvm(or rbenv)

macOS shiped with ruby

$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

install with homebrew

you could upgrade to a new ruby

brew install ruby

open a new terminal window

$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]

install with rvm

because the default version macOS shiped with is v2.0, you could install another version, say v2.2, along with v2.0

install rvm first

\curl -sSL https://get.rvm.io | bash -s stable

then install ruby v2.2 using rvm command

rvm install ruby-2.2
ruby -v

Ubuntu 16.04

sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get install ruby2.1 ruby2.1-dev ruby-switch -y
sudo ruby-switch --set ruby2.1

最早参照http://stackoverflow.com/a/32569363

更多参照官方文档:https://www.brightbox.com/docs/ruby/ubuntu/

可以删除已经安装的ppa

sudo add-apt-repository --remove ppa:brightbox/ruby-ng

How To Install Ruby with rbenv on CentOS 7 for jenkins job

Install rbenv

sudo yum install -y git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel

jenkins is Jenkins user, will run ruby

vim /etc/passwd

change /bin/false to /bin/bash to allow login to jenkins user

jenkins:x:996:994:Jenkins Automation Server:/var/lib/jenkins:/bin/false
su jenkins

Below installs rbenv into your home directory

cd
git clone https://github.com/rbenv/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
exec $SHELL

setup $PATH

bash-4.2$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin

bash-4.2$ source .bash_profile 

bash-4.2$ echo $PATH
/var/lib/jenkins/.rbenv/plugins/ruby-build/bin:/var/lib/jenkins/.rbenv/shims:/var/lib/jenkins/.rbenv/bin:/sbin:/bin:/usr/sbin:/usr/bin

As jenkins user

bash-4.2$ rbenv install -v 2.2.1
bash-4.2$ rbenv global 2.2.1
bash-4.2$ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]

Upgrade

macOS 10.12

macOS shiped with ruby, you could use rvm to upgrade to selected version.

How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?

\curl -sSL https://get.rvm.io | bash -s stable
rvm install ruby-2.2
ruby -v
rvm list

rvm rubies

=* ruby-2.2.6 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

See also

References