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 | 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




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

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

git clone ~/.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

bash-4.2$ source .bash_profile 

bash-4.2$ echo $PATH

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]


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 | 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