How to Install Ruby on Rails

Ruby on Rails (RoR), commonly known as Rails, is an open-source web framework written in Ruby, used to create highly scalable and high-performing web applications.

This article will look at how to install and set up the Ruby on Rails Framework on Linux.

NOTE: In this guide, we tested the installation process and instructions on Debian 10 system.

Install Dependencies

The first step is to update the system and set up the required dependencies.

sudo apt-get update
sudo apt—get install curl git gnupg gawk bison libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libyaml-dev pkg-config sqlite3 zlib1g-dev libgmp-dev libreadline-dev libssl-dev

Once you have the required dependencies, we can proceed to install Ruby and Ruby on Rails.

Install Ruby Version Manager

In this guide, we shall use the Ruby Version Manager to install and manage Ruby installations on our system.

RVM is easy to install and use, especially when working with multiple Ruby versions.

Start by importing and installing the GPG keys to verify the installation package.

gpg --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Ensure you have the GnuPG package installed before running the command above.

In some instances, you may get an error when importing the RVM keys. To resolve this, you can import the keys with curl and verify them manually.

Use the commands:

curl -sSL | gpg --import -

Once installed, curl the installer from Github and run it to bash using the command as:

curl -sSL | bash -s stable --ruby

If you want to install the development version of RVM, use the command:

curl -sSL | bash

Once RVM installed, use the source command to add it to your path.

source /home/debian/.rvm/scripts/rvm

You can verify that RVM is installed and available in your path using the which command:

$ which rvm

Install Ruby with RVM

In this step, we need to install the stable release of the Ruby language and make it the default Ruby Version.

To install the latest Ruby version, use the command:

rvm install ruby-3.0.2

As of writing this tutorial, the latest stable version of Ruby is version 3.0.2. Before executing the command, verify to ensure there are no newer versions.

Once the installation is successful, set the installed Ruby version as default by running the command:

rvm --default use ruby-3.0.2

To verify the applied changes, run the command:

ruby --version

Running this command should display the latest Ruby version:

ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

Setting Up NodeJS

RoR requires JavaScript runtime for processing JavaScript code in web applications. Hence, we need to install NodeJS.

In this case, we can use the LTS version of NodeJS and run the command:

curl -fsSL | bash -
apt-get install -y nodejs

Install Yarn

In the next step, import yarn. Start by importing the gpg keys using the command:

curl -sS | sudo apt-key add -

Finally, add the Yarn Debian Repository as:

echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Finally, update and install Yarn using the commands:

sudo apt-get update
sudo apt-get Yarn

Once the above installations are complete, verify by checking the versions:

node --version
yarn --version

Install Bundler and Ruby on Rails

In this step, we need to install Bundler and Ruby on Rails. Although we do not need to install gem, it is very useful for tracking Ruby projects.

Use the commands as:

gem install bundler

Once installed, use the command below to install the latest version of Ruby on Rails.

gem install rails -v 6.1.4

To install another version of Ruby on Rails, change the 6.1.4 with the targeted version.

Finally, verify the Rails version using the command:

rails -v

Rails 6.1.4

Creating Test Application

We can now test that RoR is installed and working as expected by creating a sample application. In this example, we will use the default database system for Rails, SQLite.

If you wish to learn how to use other database systems, check out the following tutorials.

To create a new rails project, start by creating a directory where the app will reside.

mkdir ~/Desktop/RoR
cd ~/Desktop/RoR

Next, initiate a new project with the command:

rails new app

The above command will create a new application with the name ‘app.’ Feel free to change the name to your desired application name.

Finally, start to navigate into the project and start the puma web server:

cd app
rails server

This will launch the puma server on http://localhost:300

Open the browser and navigate the above address. It should display the default Rails webpage.


That’s it for this tutorial. You have now successfully installed Ruby on Rails on Linux.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list