3. Installing rbenv and Ruby on Linux

Last Updated: 26 Nov 2018, Credit to: The Odin Project


sudo apt-get update
sudo apt-get upgrade

Install misc packages:

sudo apt-get install curl git nodejs gcc make libssl-dev libreadline-dev zlib1g-dev libsqlite3-dev

Install rbenv: (last command closes your terminal deliberately)

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

Get ruby plugin:

mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Install ruby: (2.5.3 was the current version as of this writing)

rbenv install 2.5.3 --verbose

Set Ruby version and verify it is installed:

rbenv global 2.5.3
ruby -v