• Nibelungenpl. 1, 60318 Frankfurt am Main, Germany
  • Mon-Fri: 09.00am - 10.00pm

How to Install Ruby and Rails on Ubuntu

Ruby is one of the most popular languages today. It has an elegant syntax and it is the language behind the powerful Ruby on Rails framework.

In this tutorial, we will show you three different ways to install Ruby on Ubuntu 20.04 system.

Prerequisites

Before starting with the tutorial, make sure you are logged in as a user with Sudo privileges.

Installing Ruby from Ubuntu Repositories

The easiest way to install Ruby on your Ubuntu system is through the apt package manager. At the time of writing, the version in the Ubuntu repositories is 2.6.5 which is the latest stable version of Ruby.

To install Ruby from the default Ubuntu repositories, follow these steps:

First, update the packages index:

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash –
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add –
echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt-get update
sudo apt-get install 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 nodejs yarn

Install Rub

Next, we’re going to be installing Ruby using one of three methods. Each have their own benefits, most people prefer using rbenv these days, but if you’re familiar with rvm you can follow those steps as well. I’ve included instructions for installing from source as well, but in general, you’ll want to choose either rbenv or rvm.

Choose one method. Some of these conflict with each other, so choose the one that sounds the most interesting to you or go with my suggestion, rbenv.

Using rbenv (Recommended)
Using rvm
From source
Installing with rbenv is a simple two-step process. First, you install rbenv, and then ruby-build:

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc
echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”‘ >> ~/.bashrc
exec $SHELL

rbenv install 2.6.5
rbenv global 2.6.5
ruby -v

The last step is to install Bundler:

gem install bundler

rbenv users need to run rbenv rehash after installing bundler.

Configuring Git
We’ll be using Git for our version control system so we’re going to set it up to match our Github account. If you don’t already have a Github account, make sure to register. It will come in handy for the future.

Replace my name and email address in the following steps with the ones you used for your Github account.

git config –global color.ui true
git config –global user.name “YOUR NAME”
git config –global user.email “YOUR@EMAIL.com”

The next step is to take the newly generated SSH key and add it to your Github account. You want to copy and paste the output of the following command and paste it here.

ssh-keygen -t rsa -b 4096 -C “your_email@example.com” [This will display keys in terminal]

Add that key to Github or bitbucket

Hi, excited! You’ve successfully authenticated, but GitHub does not provide shell access.
Installing Rails
Choose the version of Rails you want to install:

gem install rails -v 5.0.7.2

If you’re using rbenv, you’ll need to run the following command to make the rails executable available:

rbenv rehash

Now that you’ve installed Rails, you can run the rails -v command to make sure you have everything installed correctly:

rails -v

# Rails 5.0.7.2

Leave A Comment

Your email address will not be published. Required fields are marked *

Subscribe to Our Newsletter for the Weekly Updates.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
  • Attributes
  • Custom attributes
  • Custom fields
Click outside to hide the compare bar
Compare