Ruby is an open source programming language that focuses on simplicity and productivity. It becomes very popular thanks to the Ruby on Rails framework due to that lot of startups adopt it to develop their products, some like Github with lot of sucess.
I choose to install Ruby using rbenv instead of the official linux package, because rbenv will help us to manage different Ruby environments.
Also I prefer to install rbenv from source instead of using the official package. The rbenv package version usually is outdated and from source is easiest to upgrade.
1 rbenv
1.1 Install rbenv
Install necessary packages:
sudo apt -y install build-essential git-core libssl1.0.0 libssl-dev libreadline-dev zlib1g-dev
Clone rbenv repository into .rbenv directory:
git clone git@github.com:rbenv/rbenv.git ~/.rbenv
Optionally, try to compile dynamic bash extension to speed up rbenv. Don’t worry if it fails; rbenv will still work normally:
cd ~/.rbenv && src/configure && make -C src
1.2 Install ruby-build
ruby-build will help us to install any version of Ruby.
Clone ruby-build repository into .rbenv/plugins:
git clone git@github.com:rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
1.3 Set up shell
Add this to .zshrc or .bashrc & reload the shell:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
2 Ruby
List stable ruby versions:
rbenv install -l
Install latest stable ruby:
rbenv install 3.1.2
Set the version installed as global:
rbenv global 3.1.2
3 Upgrading
Upgrade rbenv:
cd ~/.rbenv
git pull
Upgrade ruby-build:
cd ~/.rbenv/plugins/ruby-build
git pull