How to Install Ruby on Rails on Ubuntu 18

How to Install Ruby on Rails on Ubuntu 18

Introduction

Ruby on Rails is a powerful web application framework designed to help developers create new projects while scripting less code. It is a popular open-source package that is published under the Massachusetts Institute of Technology (MIT) license and features a server-side web framework that leverages the Model View Controller (MVC) concept. The application makes web development great fun thanks to the support of the well-versed community that delivers commendable contributions to make the package better.

This tutorial will show you how to install Ruby on Rails on Ubuntu 18.04 via the command line tool Ruby Version Manager (RVM). Setting up Ruby on Rails (RoR) on Ubuntu is an excellent idea because most of the codes you create will run on this easy-to-use Linux distribution. On the other hand, the RVM presents a robust development workspace that allows you to work with numerous Ruby environments and switch between them seamlessly.

Ready? Let’s roll!

Updating The GNU Privacy Guard (GPG)

The first step when installing RoR on Ubuntu 18.04 is updating the GPG to the latest version. This makes it easy to contact the public key server and request a key linked to the given ID. To update the GNU Privacy Guard run the following command:

$ sudo apt install gnupg2

Note: we’ve utilized a user with sudo privileges to update the GPG, but all the other commands in this tutorial can be implemented without sudo privileges.

Installing RVM Packages

Once you update the GPG, the next step is installing all the required Ruby Version Manager packages. First, request the RVM project’s public key to validate each RVM release.

The RVM project’s key permits you to authenticate the validity of the RVM release that you will download. Run the command below to add the RVM key to your server:

$ gpg2 --keyserver hkp://keys.gnupg.net --recv-keys409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Next, move to a rewritable environment such as /temp directory and download the Ruby Version Manager script into the file:

$cd /tmp

Now, we have to leverage a curl command to download the required RVM installation script from the RVM project’s website. Here the backlash that directs the command makes sure the curl command used is regular and not an alias version.

We’ll include the -s flag to signify the utility should function in a silent mode. In addition we append -S flag that allows curl to display errors whenever it fails. The command will also include -L flag to enable the utility to follow the redirects, and -o flag that indicates to write the output to a file rather than a standard output.

When all these elements are combined, what you get is a complete command:

$ curl -sSL https://get.rvm.io -o rvm.sh

To audit the content of this RVM script before implementing it, run the command below:

$ less /tmp/rvm.sh

Next, pipe the RVM installation script to bash to install the most recent version of stable Rails. The Rails version will automatically pull in all the associated stable versions of Ruby.

$ cat /tmp/rvm.sh | bash -s stable --rails

Note: You may be required to provide your valid user’s password during the installation.

Once the installation is done, look for the Ruby Version Manager scripts from the location they were installed. In most cases, the directory for the RVM scripts is home/username. Run the command below to source the scripts:

$ source/home/username/.rvm/scripts/rvm

By now you have a fully configured  Ruby on Rails (RoR) environment.

Installing A Specific RoR Version

If you are a fun of a specific Ruby on Rails version that is not the latest one, you can install it using the RVM.

First, run the command below to check the available Ruby versions:

$ rvm list known

Next, run the command below to install the Ruby version that you want using the RVM.

$ rvm install ruby_version

The ruby_version can be put as ruby-2.4.0 or just 2.4.0 in the above command.  Once the installation is done you can view a list of the Ruby versions you have installed by running the command below:

$ rvm list

If you want to switch between these versions, just type:

$ rvm use ruby_version

Where ruby_version stands for the version you want to use such as ruby-2.4.0.

Better still, Rails is a gem which means we can use the gem command to install its versions. To accomplish this, we first search for all the available Rails’ versions using the command below:

$ gem search '^rails$' --all

Next run the command below to install the required Rails version:

$ gem install rails -v rails_version

Note:rails_version stands for the version number such as 5.1.6

In addition, various Rails versions can be used with each Ruby. To achieve this, we create gemsets and install Rails with the sets using the gem commands.

First, run the command below to create the gemset:

$ rvm gemset create gemset_name

Next, run the command below to specify the version of Ruby to use:

$ rvm ruby_version@gemset_name  --create

The gemsets create a self-contained environment for the gems and multiple environments for every Ruby version you have installed.

Installing The JavaScript Runtime

Some of the Rails features like the Asset Pipeline are designed to depend on JavaScript Runtime. For this reason, it’s good you install the functionality to complement your RoR package. To accomplish this, we install the Node.js with a package manager apt.

Note: we’ll move to a writable location, output the Node.js script to a file to authenticate it, and use less to read it.

$cd /tmp
$ curl -sSL https://deb.nodesource.com/setup_10.x -o nodejs.sh
$ less nodejs.sh

Run the command below to install NodeSource Node.js v10.x repo:

 $ cat /tmp/nodejs.sh | sudo -E bash -

The -E flag preserves the existing environment variable of the user.

Next, run the commands below to update apt and then use it to install the Node.js:

$ sudo apt update
$ sudo apt install -y nodejs

Conclusion

That it! The tutorial has covered all the basics of installing Ruby on Rails using the Ruby Version Manager. You can now use Ruby on Rails to create new web applications.

Check out these top 3 Linux hosting services

Webdock
£0.80 /mo
Starting price
Visit Webdock
Rating based on expert review
  • User Friendly
    3.8
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.3
  • Pricing
    4.3
Kamatera
£3.05 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
Ultahost
£1.90 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How To Install PostgreSQL Database Server On Ubuntu 18.04?

This tutorial will help you install PostgreSQL; an advanced open source database
less than a minute
David Malcom
David Malcom
Author

How to backup PostgreSQL database on Ubuntu 18

It is crucial to ensure users' data is not lost in case of any misfortune, wheth
less than a minute
Kennedy Mbuvi
Kennedy Mbuvi
Author

How to Set Up Replication on PostgreSQL on Ubuntu 18.04 VPS or Dedicated Server

High availability and load balancing are important concepts in database manageme
less than a minute
Vladimir Rakov
Vladimir Rakov
Hosting Expert

How to Install Ruby on Rails on a Windows VPS or Dedicated Server

This guide shows you how to install the Ruby on Rails web framework on Windows.
less than a minute
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top