Install ruby on Ubuntu 20.04

Written by
Date: 2020-05-16 18:05:00 00:00

Installing ruby on Ubuntu 20.04 using rbenv is at the time of this writing the most recommenden method.

First things first, update your computer.

sudo apt update && sudo apt upgrade

Then install dependencies

sudo apt install zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev

Now install rbenv, be sure not to be logged as root, but as the user that will use ruby, and at your home directory.

cd

That command will take you to your home folder.

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
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"' >> ~/.bashrc
exec $SHELL

Now install ruby,

rbenv install 2.6.6
rbenv global 2.6.6
ruby -v

I am installing 2.6.6 version, but you can choose another one.