Qadry
unixcop Admin

How to Install Ruby on Ubuntu

Introduction

Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.

Ruby is seen as a flexible language, since it allows its users to freely alter its parts. Essential parts of Ruby can be removed or redefined, at will. Existing parts can added upon. Ruby tries not to restrict the coder.

 The language serves as the basis of the Ruby on Rails framework and is used for general-purpose programming, data analysis, and web applications.

Ruby can be used in diverse applications such as data analysis and prototyping.

In this installation guide, you will learn how to install Ruby on Ubuntu 20.04 with three different methods.

If you want to install Ruby On CentOS / RHEL 8 , Kindly visit this article Ruby on CentOS 8

You may also need to install Ruby on Rails, So visit this article Ruby on Rails on CentOS 8

Installation

Method [1]

Install Ruby from Ubuntu repository

We will install it via Appstream Repository

So just follow the steps:

  • Update the system’s packages and repositories with:
sudo apt update -y
  • Install Ruby with the command below
sudo apt install ruby-full -y
  • Verify Ruby by checking the current version of it
ruby --version

Method [2]

Install Ruby on CentOS 8 using the RVM Manager

So RVM (Ruby Version Manager) is a command-line tool that allows you to install and work with multiple Ruby environments.

So just follow the steps below:

  • Update the system repositories by using:
sudo apt update -y
  • Download and install dependencies of Ruby need to install it.
sudo apt install curl g++ gcc autoconf automake pkg-config sqlite3 zlib1g-dev libc6-dev libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev bison libtool libyaml-dev make libgmp-dev libreadline-dev libssl-dev -y
  • Install RVM by adding the GPG key used to verify the RVM installation file
gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  •  Download and install RVM using the installation script as follow
curl -sSL https://get.rvm.io | bash -s stable
  •  Load the RVM script environment variables
source ~/.rvm/scripts/rvm
  • List all versions of Ruby available.
rvm list known

Note: At this time, the latest version of Ruby is 3.0.2 as shown above in the screenshot.

  • Install the latest stable version of Ruby using the RVM without selecting a specified version by default or by selecting the version you need
rvm install ruby          #this will install the latest stable version in rvm list.
OR
rvm install ruby 3.0.2    #this will specify the version that you want to install.
  • Also Verify the version of Ruby.
ruby --version

A 3.0.0 version of ruby has been installed.

  • Set the new version of Ruby as the default:
rvm --default use ruby-[version number]

Method [3]

Install Ruby with Rbenv

Rbenv is a lightweight Ruby version management utility which allows you to switch between Ruby versions.

Use the ruby-build plugin to extend the core functionality of Rbenv also to allow you to install any Ruby version.

So follow the steps below:

  • Download and run the shell script used to install Rbenv
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
  • You need to add $HOME/.rbenv/bin to your PATH environment variable to start using Rbenv by running the commands below.
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
  • Verify the installation by checking the version of Rbenv
rbenv -v
  • List all of the versions of Ruby available for installation with Rbenv
rbenv install -l
  • Select a version of Ruby and install it.
rbenv install [version number]
  • We are installing Ruby 3.0.2:
rbenv install 3.0.2
  • Verify the installation
ruby --version
  • Set the newly installed version of Ruby as the global version
rbenv global [version number]
  • We are setting the version 3.0.2.
rbenv global 3.0.2

Conclusion

In this installation guide, we shew you three different methods to install Ruby on your Ubuntu. The method you choose depends on your requirements and preferences.

That’s all !! Thank you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x