Share your love
How To Set Up Ruby on Rails on Ubuntu 20.04

In this guide, we want to teach you How To Set up Ruby on Rails on Ubuntu 20.04. Ruby on Rails (sometimes RoR) is the most popular open-source web application framework. It’s built with the Ruby programming language.
You can use Rails to help you build applications, from simple to complex; there are no limits to what you can accomplish with Rails! Now, proceed to the guide steps on the Orcacore website to install and configure Ruby on Rails on Ubuntu 20.04.
Table of Contents
How To Set Up Ruby on Rails on Ubuntu 20.04?
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on the Initial Server Setup with Ubuntu 20.04.
In this tutorial, you will learn to install Ruby on Rails with RVM.
RVM, or Ruby Version Manager, is a command-line tool that lets you manage and work with multiple Ruby development environments and allows you to switch between them.
1. Install RVM and Rails on Ubuntu 20.04
First, you need to update your local package index with the following command:
sudo apt update && sudo apt upgrade -y
Then, you need to install or update GPG to the most recent version to contact a public key server and request a key associated with the given ID:
sudo apt install gnupg2 -y
Next, you must request the RVM project’s public key to verify the legitimacy of your download with the following command:
sudo gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Now use the following command to download the RVM script installer and write it to a file named rvm.sh:
sudo \curl -sSL https://get.rvm.io -o rvm.sh
When your download is completed, you can pipe it to bash
to install the latest stable Rails version, which will also pull in the associated latest stable release of Ruby by running the command below:
cat rvm.sh | sudo bash -s stable --rails
When your download is completed, you will get the following command:

Next, source the RVM scripts with the following command:
source /usr/local/rvm/scripts/rvm
2. Install a Specific Version of Ruby on Ubuntu 20.04
To install a specific version of Ruby, you can use the RVM. First, check to see which versions of Ruby are available by listing them:
rvm list known
You will get the following output:

Then, install the specific version of Ruby that you need through RVM, replacing the highlighted version number with your version of choice, such as ruby-3.0.0
or just 3.0.0
:
rvm install 3.0.0
Output
Already installed ruby-3.0.0.
To reinstall use:
rvm reinstall ruby-3.0.0
You can list available Ruby versions you have installed by typing:
rvm list
Output
=* ruby-3.0.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Since Rails is a gem, which is a standardized format that contains Ruby programs, you can also install various versions of Rails by using the gem
command.
List the valid versions of Rails with the following command on Ubuntu 20.04:
gem search ^rails
Output
*** REMOTE GEMS ***
rails (7.0.3.1, 7.0.3, 7.0.2.4, 7.0.2.3, 7.0.2.2, 7.0.2.1, 7.0.2, 7.0.1, 7.0.0, 6.1.6.1, 6.1.6, 6.1.5.1, 6.1.5, 6.1.4.7,...
Next, you can install your required version of Rails. Replace the highlighted version number with your version of choice, such as 7.0.3.1
.
gem install rails -v 7.0.3.1
Output
Successfully installed rails-7.0.3.1
Parsing documentation for rails-7.0.3.1
Done installing documentation for rails after 0 seconds
1 gem installed
You can use various Rails versions with each Ruby by creating gemsets and then installing Rails within those using the normal gem
commands.
To create a gemset, you will use:
rvm gemset create gemset_name
Output
ruby-3.0.0 - #gemset created /usr/local/rvm/gems/ruby-3.0.0@gemset_orca
ruby-3.0.0 - #generating gemset_orca wrappers........
To specify a Ruby version to use when creating a gemset, use:
rvm 3.0.0@gemset_name --create
Output
Using /usr/local/rvm/gems/ruby-3.0.0 with gemset gemset_orca
The gemsets allow us to have self-contained environments for gems as well as multiple environments for each version of Ruby that you install.
For more information, you can visit the Ruby on Rails Guides page.
Conclusion
At this point, you learn to set up Ruby on Rails with RVM on Ubuntu 20.04. RVM simplifies managing Ruby versions, gemsets, and dependencies, making development smoother and more organized. Once installed, you’re ready to build powerful web applications with the full Rails stack in a clean, isolated setup. It’s a solid foundation for any Rails project on Ubuntu.
Hope you enjoy using it. You may be interested in these articles:
Install and Configure Lighttpd on Ubuntu 20.04
Install Symfony PHP Framework on Ubuntu 20.04