Install Ruby on Ubuntu 22.04

Ruby is the one of most commonly used open-source and interpreted scripting programming languages designed to develop front and back-end web applications with the help of Ruby Rails framework. This programming language is also utilized for data analysis and general-purpose programming. It also enables the users to build and deploy scalable app quickly.

Ruby can be installed using different methods on Ubuntu 22.04. In this post, you will learn about the installation of Rubyon Ubuntu 22.04 using the Ubuntu repository, RVM, and Rbenv. Let’s start!

Method 1: Install using Ubuntu 22.04 repository

The built-in apt package manager is used to install Ruby on Ubuntu 22.04. Follow the given below steps:

Step 1: Update packages

To update system packages on Ubuntu 22.04, firstly, open up the terminal by pressing “CTRL+ALT+T” together and execute the given-below command:

$ sudo apt update

Now, upgrade the system packages with the help of the below-given command:

$ sudo apt upgrade

Step 2: Install Ruby on Ubuntu 22.04

Next, install Ruby on Ubuntu 22.04, by utilizing the provided command:

$ sudo apt install ruby-full

Press “Enter” to continue the installation process:

Here, you can see Ruby is installed successfully:

Step 3: Check the Version

After installing Ruby, verify its existence by checking its version:

$ ruby --version

The below-given output signifies that we have successfully installed Ruby version “3.0.2p107” on our system:

How to remove Ruby from Ubuntu 22.04

If you want to remove Ruby from Ubuntu 22.04, run the given below command in terminal:

$ sudo apt remove --autoremove ruby

Then type “Y” and press “Enter” to continue the uninstallation process:

Now, let’s check out the second method for the installation of Ruby on Ubuntu 22.04.

Method 2: Install RVM-Ruby Version Manager

RVM is a command-line utility that allows the user to easily install, manage and work with multiple environments of Ruby on the same system. Follow the given below steps to install Ruby using RVM:

Step 1: Update packages

First of all, update the Ubuntu 22.04 system packages using below command:

$ sudo apt update

Now move to the next instruction.

Step 2: Add dependencies

After updating the system packages, install the essential dependencies Ruby needs to run properly. Install it utilizing the command:

$ 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

Required dependencies are installed successfully.

Step 3: Import GPG key

Next, import the GPG key in your system by using the following “gpg” command:

$ gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Step 4: Install RVM

Now, download and install RVM with the help of the installation script:

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

RVM is installed successfully, now move to the next instruction.

Step 5: Load RVM Script Environment

After the installation of RVM, execute the given-below “source” command to load RVM script environment:

$ source ~/.rvm/scripts/rvm

Step 6: Get Ruby language on Ubuntu 22.04

Now, list all the available versions of Ruby first through RVM:

$ rvm list known

Step 7: Install any Ruby version

Now, select the version of Ruby according to your requirements and install it using following syntax:

$ rvm install ruby-3.1.2

In the above-given command, you can specify your selected Ruby version and execute it in the terminal:

The next section will demonstrate the method to install Ruby using Rbenv.

Method 3: Ruby install using Rbenv

Rbenv is also a command-line utility that enables the user to install the latest available version of Ruby on Ubuntu 22.04. The given-below steps are required to install the Ruby using Rbenv:

Step 1: Update packages

Update the Ubuntu 22.04 system packages using below command:

$ sudo apt update

Given-above output indicates that the system packages are updated successfully.

Step 2: Add dependencies

Next, you have to install the essential dependencies for Ruby utilizing the following command:

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

Now move to the next instruction.

Step 3: Get Rbenv installation script:

Now, to get the Rbenv installation script run the mentioned below command in your Ubuntu 22.04 terminal:

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

Step 4: Add Directory Path

To utilize Rbenv command-line tool, add the directory path to your system path:

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

Directory path is added successfully and now moves to the next step.

Step 5: Check the Version

After installing Rbenv on Ubuntu 22.04, verify its existence by checking its version:

$ rbenv -v

The below-given output signifies that we have successfully installed Rbenv version “1.2.0-14-gc6cc0a1” on our system:

Step 6: List Ruby Versions

Rbenv installation is completed, now check the Ruby versions using the “rbenv” command with “-l” option:

$ rbenv install -l

The above output shows the available version of Ruby on Ubuntu 22.04 utilizing the “rbenv” command.

Step 7: Install of Ruby on Ubuntu 22.04

Now, select suitable version of Ruby and install it through given-below command:

As you can see, Ruby is installed successfully, now let’s move to the next instruction.

Step 8: Check Ruby version

To check the version of installed Ruby, utilize the “ruby” command with the “–version” option:

$ ruby --version

The below-given output indicates that we have successfully installed Ruby version “3.0.2p107” on our Ubuntu 22.04 system:

That was all essential information related to installing Ruby on Ubuntu 22.04 using the multiple methods. You can further explore as required.

Conclusion

There are several ways or methods to install Ruby on Ubuntu 22.04, including Ubuntu repository by executing the “$ sudo apt install ruby-full” command or through the Rbenv command-line, with the help of the “$ rbenv install ruby 3.1.2” command or by utilizing RVMcommand-line with “$ rvm install ruby-3.1.2” command. In this post, we have discussed different methods to install Ruby on Ubuntu 22.04, including Ubuntu repository, Rbenv, and RVM.