How to install Ruby 3 on Ubuntu 20.04

ruby is an open source, object-oriented and universal programming language that is one of the most popular programming languages. The Ruby programming language is the reason for the powerful Ruby and Rails framework.

There are several Ruby managers available for installing Ruby. Ruby managers allow multiple versions to be used and help switch between Ruby versions. The most commonly used Ruby managers are rbenv and rvm. Ruby is also available in the Ubuntu repository.

In this article we will get to know three different ways to Install Ruby 3 on Ubuntu 04/20.

requirements

  1. Ubuntu 20.04 installed system
  2. Account with sudo permissions

  3. Proper internet connection for downloading applications.

Method 1- Install Ruby using Rbenv

Many Rubyists in the community prefer to install Ruby with rbenv. Rbenv is a tool that can be used to switch between different versions of Ruby. However, this tool cannot be used to install Ruby.

You will need another tool to install Ruby Ruby construction. Use the following command to update the Ubuntu 20.04 repository to the latest index.

$ sudo apt update

Run the following command to install dependencies.

$ sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential        libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev

After installing the dependencies, run the following command to clone both of them Rbenv and Ruby build Repositories at Github.

$ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash

Now run the following commands to set PATH in .bashrc:


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

Now you can install any available version of Ruby using Rbenv. Run the following command to list the versions available.

$ rbenv install -l

You will receive the output as:


List available Ruby versions

You can install the version you want by running the following command. For this article, I am installing Ruby 3.0.0.

$ rbenv install 3.0.0

This will take a few minutes.

To set the global variable, run the following command:

$ rbenv global 3.0.0

Replace the version number with your environmentally compatible version.

Run the following command to check the installed Ruby version:

$ ruby -v

You will get output similar to:

output:

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

Method 2- install Ruby from Ubuntu repositories

The easiest and easiest way to install Ruby is to use the built-in Ubuntu apt package manager. The version of Ruby installed with the standard apt package manager is usually the most recent.

Run the following command to update Ubuntu repositories to the latest index.

$ sudo apt update

Use the following command to install Ruby.

$ sudo apt install ruby-full

After the installation is complete, run the following command to verify that Ruby is installed:

$ ruby --version

You’ll get the output similar to:

output:

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

The output verifies the installation of Ruby version 3.0.0

Method 3 – Install Ruby with RVM

Another tool for installing and managing Ruby on Ubuntu and other Linux systems is RVM.

To install RVM on Ubuntu 20.04, follow the steps below:

Update the Ubuntu repositories to the latest index using the following command:

$ sudo apt update

Run the following command to install RVM dependencies:

$ sudo apt install curl g++ gcc autoconf automake bison libc6-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool libyaml-dev make pkg-config sqlite3 zlib1g-dev libgmp-dev libreadline-dev libssl-dev

Now run the following command to install RVM:

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

$ curl -sSL https://get.rvm.io | bash -s stable

Run the following command to Activate RVM:

$ source ~/.rvm/scripts/rvm

Now you can install Ruby with the following command:

$ rvm install 3.0.0

You can replace the version number with your compatible version

To use installed Ruby as the default, run the following command:

$ rvm use 3.0.0 --default

Run the following command to verify your installation:

$ ruby -v

You will get output on your screen similar to:

output:

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

The installed Ruby version is 3.0.0

diploma

In this article, you learned about different methods to install Ruby 3 on Ubuntu 20.04. You also learned how to review your Ruby installation and install different versions that are compatible with your environment.