3 Ways to Install Ruby on Ubuntu 22.04 LTS Jammy

Learn the different commands and steps to install Ruby on Ubuntu 22.04 LTS Jammy JellyFish using the command terminal.

Ruby is an object-oriented high-level interpreted programming language that is easy to use and productive to use. Inventor Yukihiro Matsumoto wanted to develop a language in which functional and imperative programming is balanced, hence, this dynamic, free and object-oriented programming language Ruby enjoys great popularity among programmers.

Everything in Ruby is an object that allows any programmer to customize the language to their preferences. In contrast to some others, the syntax is easier to read and write. It is similar to C and Java, so Java and C programmers can easily learn Ruby.

An extensive Online Documentation introduces newcomers to ruby syntax. Many Ruby projects are in the RubyForge, where you can also search for new libraries.

It offers a powerful package manager for distributing Ruby programs and libraries, in a standalone format called “gem”, as well as tools to easily manage the installation of gems on a server. Ruby programmers also have access to the powerful features of RubyGems.

Ruby supports all major platforms such as Windows, Mac, and Linux.

Steps to install Ruby on Ubuntu 22.04 LTS

There are three simple ways to install Ruby on Ubuntu Linux here we show all of them. Also, the steps are given here can be used for other Ubuntu versions such as 20.04/18.04 including other Linux – Mint, Debian, Elementary OS, MX Linux, POP_OS, and more…

#1st method using Ubuntu standard repository  

1. Run system update

Let’s first run the system update command that will let our system’s package manager know about the latest packages available through the system repositories.

sudo apt update

 

2. Install Ruby on Ubuntu 22.04

Yes, we can install Ruby programming language using Ubuntu’s default repository, however, the version of it will not be the latest one instead of the well stable and tested because Ubuntu 22.04 is a Long Term supported version. Hence, if you want to get the Ruby without adding any extra repo, then use the given command:

sudo apt install ruby-full

Install Ruby on Ubuntu 22.04

Once the installation is completed, we can check the version using:

ruby --version

 

#2nd method using Rbenv

3. Install Rbenv

Rbenv is a command-line tool that lets us manage multiple Ruby versions and switch between them. We can also use it to install the latest versions of Ruby using the ruby-build plugin.

Install required dependencies: 

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

Get Rbenv installation script:

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

Add a directory path that holds Rbenv files to your system path to use its command-line tool:

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

To check the installed version:

rbenv -v

 

4. Install Ruby using Rbenv

Now, Rbenv is ready to use on your Ubuntu 22.04 system, we can use it to list and install any latest version of Ruby on our system.

To list the available versions to install we can use:

rbenv install -l

rbenv install l

To install the any of the listed versions we can use the given syntax:

rbenv install  version

Replace the “version” in the above syntax with the one you want to install. For example, if you want to install 3.1.2  then the command will be:

rbenv install 3.1.2

 

How to set the system-wide default Ruby version:

As we know we can use rbenv to install and manage multiple versions of Ruby. Therefore, if you have the more than two versions on your system and want to set one of them as your system’s default version then the syntax is:

rbenv global version

Replace the “version” with what you want to set as the system-wide default one.

For example:

rbenv global 3.1.2

To remove any ruby version:

rbenv uninstall version

 

#3rd method using Install Ruby Using RVM- Ruby Version Manager

5. Install RVM- Ruby Version Manager

Another way to install Ruby on our Ubuntu 22.04 is using another command-line tool called RVM– Ruby Version Manager.

Ruby Version Manager in short RVM, is a software platform developed to manage multiple installations of Ruby on the same device that includes the entire ruby environment including the Ruby interpreter and installed RubyGems. This helps the developers to easily switch between different Ruby versions as per the requirement of different projects.

Install 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

Install GPG key

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

Get RVM:

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

After that source the variables:

source ~/.rvm/scripts/rvm

 

6. Get Ruby language on Ubuntu 22.04

Finally, we can use RVM to install available Ruby versions, to list them we can use the given command:

rvm list known

RVM list Ruby versions

To install any specific version listed after running the previous command, you can use:

rvm install ruby-version

Replace “version” in the above command with the one you want to install, for example, let’s say you want to have 3.1.2

rvm install ruby-3.1.2

Whereas to simply install whatever the latest version is available, use:

rvm install ruby

How to use RVM to set a specific Ruby version as the system’s default one;

rvm --default use ruby-version

Replace “version” in the above command with the one you want to install

To remove any ruby version:

rvm remove ruby-version

 

7. Uninstall or remove

As per the method you have used to install Ruby,  you can remove the same using the given commands:

To remove APT installed Ruby

sudo apt remove ruby-full

To remove Rbenv

rm -rf ~/.rbenv

To remove RVM

rvm implode
rm -rf ~/.rvm
rm -rf /etc/rvmrc
rm -rf ~/.rvmrc

 

Other Articles:

How to Install Maven on Ubuntu 22.04 LTS Jammy
How to install CUDA on Ubuntu 20.04 LTS…
Ubuntu 22.04 Remote Desktop Access from Windows…
4 Ways to install Firefox browser on Ubuntu 22.04…

 

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.