Ruby relies on several packages which you can install through your package manager. Once those are installed, you can install rbenv and use it to install Ruby.

$ sudo apt update
$ sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev -y

Next step is to clone 'rbenv' from the source repository into "~/.rbenv" and add it to path.

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

To verify rbenv is installed run the following command:

$ type rbenv

This will be the output:

rbenv ()
    local command;
    if [ "$#" -gt 0 ]; then
    case "$command" in
        rehash | shell)
            eval "$(rbenv "sh-$command" "$@")"
            command rbenv "$command" "$@"

To install ruby-build plugin run the following command:

$ git clone ~/.rbenv/plugins/ruby-build

You have both rbenv and ruby-build installed. Good job!

Installing Ruby

Let's install Ruby 2.7.1 by typing:

$ rbenv install 2.7.1

Once it’s done installing, set it as your default version.

$ rbenv global 2.7.1

Verify Ruby is installed by running the following command:

$ ruby -v

The output will be something like this:

ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]