We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Install Ruby on Ubuntu 22.04|20.04|18.04

Learn how to – How To Install Ruby on Ubuntu 22.04|20.04|18.04.

In this guide, we will look at how to Install Ruby Programming Language on Ubuntu 22.04/20.04/18.04 Linux machine. Ruby is a dynamic, open source, object-oriented scripting language created with simplicity and productivity in mind.

The easiest way to Install Ruby on Ubuntu 22.04/20.04/18.04 is from a PPA repository. For this, we will use the Brightbox PPA repository. Brightbox has been providing optimized Ruby packages for Ubuntu for years.

We will also consider other methods of installation Ruby on Ubuntu 22.04/20.04/18.04:

  • Install Ruby using RVM
  • Install Ruby using Rbenv

Method 1: Install Ruby on Ubuntu 22.04|20.04|18.04 using RVM

You can also install Ruby using RVM. RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

Install key dependency packages:

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

Import RVM GPG key:

$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: key 3804BB82D39DC0E3: new key but contains no user ID - skipped
gpg: Total number processed: 2
gpg:           w/o user IDs: 1
gpg:               imported: 1

# OR
curl -sSL https://rvm.io/mpapis.asc | sudo gpg --import -
curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg --import -

Then install RVM on Ubuntu 20.04/18.04 by running the command:

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

Sample successful installation output:

Installing RVM to /home/learnhowto/.rvm/
    Adding rvm PATH line to /home/learnhowto/.profile /home/learnhowto/.mkshrc /home/learnhowto/.bashrc /home/learnhowto/.zshrc.
    Adding rvm loading line to /home/learnhowto/.profile /home/learnhowto/.bash_profile /home/learnhowto/.zlogin.
Installation of RVM in /home/learnhowto/.rvm/ is almost complete:

  * To start using RVM you need to run `source /home/learnhowto/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM  
Please consider donating to our open collective to help us maintain RVM.

   Donate: https://opencollective.com/rvm/donate

You can check version:

$ rvm --version
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

Install dependencies by running the command:

$ rvm requirements run
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system..
Installing required packages: 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...............................
Requirements installation successful.

List available stable releases of Ruby

$ rbenv install -l
2.6.10
2.7.6
3.0.4
3.1.2
jruby-9.3.4.0
mruby-3.0.0
rbx-5.0
truffleruby-22.1.0
truffleruby+graalvm-22.1.0

Install Ruby with the rvm install commands. You can check Ruby releases to get version number.

$ rvm install 3.1.2
Searching for binary rubies, this might take some time.
No binary rubies available for: ubuntu/22.04/x86_64/ruby-3.1.2.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for ubuntu.
Requirements installation successful.
Installing Ruby from source to: /home/jkmutai/.rvm/rubies/ruby-3.1.2, this may take a while depending on your cpu(s)...
ruby-3.1.2 - #downloading ruby-3.1.2, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 19.6M  100 19.6M    0     0  39.2M      0 --:--:-- --:--:-- --:--:-- 39.2M
No checksum for downloaded archive, recording checksum in user configuration.
ruby-3.1.2 - #extracting ruby-3.1.2 to /home/jkmutai/.rvm/src/ruby-3.1.2.....
ruby-3.1.2 - #configuring..........................................................................
ruby-3.1.2 - #post-configuration..
ruby-3.1.2 - #compiling........................................................................................................................................................................-
ruby-3.1.2 - #installing.....................
ruby-3.1.2 - #making binaries executable...
Installed rubygems 3.3.7 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation.
ruby-3.1.2 - #gemset created /home/jkmutai/.rvm/gems/ruby-3.1.2@global
ruby-3.1.2 - #importing gemset /home/jkmutai/.rvm/gemsets/global.gems..........................................................
ruby-3.1.2 - #generating global wrappers........
ruby-3.1.2 - #gemset created /home/jkmutai/.rvm/gems/ruby-3.1.2
ruby-3.1.2 - #importing gemsetfile /home/jkmutai/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-3.1.2 - #generating default wrappers........
ruby-3.1.2 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-3.1.2 - #complete

Generate documentation:

$ rvm docs generate-ri
Generating ri documentation....................................................................................................................................................................-

To list available Ruby interpreters, use:

$ rvm list known

Confirm Ruby version:

$ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]

Method 2: Install Ruby on Ubuntu 22.04|20.04|18.04 from PPA repository

NOTE: with this method you won’t get the latest release of Ruby installed on your system.

I like the Brightbox PPA repository because it gives you the flexibility to install any version of Ruby they maintain and update from package manager:

Add PPA repository to your Ubuntu 22.04/20.04/18.04 system using the commands:

# Ubuntu 22.04
echo "deb https://ppa.launchpadcontent.net/brightbox/ruby-ng/ubuntu/ focal main"|sudo tee  /etc/apt/sources.list.d/brightbox.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys  80F70E11F0F0D5F10CB20E62F5DA5F09C3173AA6

# Ubuntu 20.04/18.04
sudo apt update
sudo apt -y install software-properties-common
sudo apt-add-repository ppa:brightbox/ruby-ng

Hit <ENTER> key when asked to proceed with PPA repository addition:

Ubuntu packages for Ruby 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0 1.9.3 and 1.8.

See https://www.brightbox.com/docs/ruby/ubuntu/ for more details.

Discussion list here:

https://groups.google.com/forum/#!forum/brightbox-ruby-ubuntu-packaging

https://www.brightbox.com
 More info: https://launchpad.net/~brightbox/+archive/ubuntu/ruby-ng
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:2 http://mirrors.digitalocean.com/ubuntu focal InRelease [265 kB]
Get:3 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu focal InRelease [23.8 kB]
Hit:4 http://mirrors.digitalocean.com/ubuntu focal-updates InRelease
Hit:5 http://mirrors.digitalocean.com/ubuntu focal-backports InRelease
Get:6 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu focal/main amd64 Packages [4508 B]
Get:7 http://ppa.launchpad.net/brightbox/ruby-ng/ubuntu focal/main Translation-en [2568 B]
Fetched 296 kB in 1s (331 kB/s)
Reading package lists... Done

After the repo is added, update your packages list:

sudo apt update

Then install the version of Ruby you want. For me, I’m installing Ruby 2.7:

$ sudo apt install ruby2.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  fonts-lato javascript-common libjs-jquery libruby2.7 rake ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby-xmlrpc rubygems-integration
  unzip zip
Suggested packages:
  apache2 | lighttpd | httpd bundler
The following NEW packages will be installed:
  fonts-lato javascript-common libjs-jquery libruby2.7 rake ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby-xmlrpc ruby2.7
  rubygems-integration unzip zip
0 upgraded, 14 newly installed, 0 to remove and 47 not upgraded.
Need to get 7853 kB of archives.
After this operation, 34.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Among the Ruby packages maintained by Brightbox – 2.7, 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0 1.9.3 and 1.8. Example to install Ruby 2.6, use:

sudo apt install ruby2.6

Once installed, check version:

$ ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux-gnu]

That’s all. You now have Ruby installed on Ubuntu 22.04/20.04/18.04 system. We hope this guide helped you start your Ruby Apps development on Ubuntu system.

Check more guides we have on Ubuntu:

Best Books To Learn Ruby App Development

Install Wekan Kanban Board system on Ubuntu

Install and Configure Tripwire on Ubuntu

Check version of Installed Package on Ubuntu / Debian

Cart

Your Cart is Empty

Back To Shop