How to Install Ruby on Rails on Ubuntu 20.04

Install Ruby on Rails on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure Ruby on Rails on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Ruby on Rails simply known as Rails, is an open-source web application framework written in Ruby that helps you create highly powerful web sites and applications. It helps them create applications and websites by abstracting and simplifying the repetitive tasks faced during development. It is called Ruby on Rails because Rails is written in the Ruby programming language, exactly how Symfony and Zend are written in PHP and Django in Python.

Install Ruby on Rails on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Dependencies for Ruby and Rails.

Install required packages for Ruby on Rails installation:

sudo apt install curl gnupg2 dirmngr git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev

Step 3. Install Node.js.

Now add the Nodejs Nodesource repository:

curl -sL | sudo -E bash -

Then, install Node.js using following command:

sudo apt install nodejs

Step 4. Install Yarn.

Now add the GPG key and repository of the Yarn package manager:

curl -sL | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Install Yarn with the using command:

sudo apt update
sudo apt install yarn

Step 5. Install Ruby.

First, you install rbenv, and then ruby-build:

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

git clone ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

Install and set Ruby v2.7.1 as the default version for all login:

rbenv install 2.7.1
rbenv global 2.7.1

Step 6. Install Rails.

Now we use gem to install rails command to install the latest stable release of Rails:

gem install rails

Once all installation is completed, check the Ruby on Rails version:

rails -v

That’s all you need to do to Ruby on Rails on Ubuntu 20.04 Focal Fossa. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.