How to install ruby on rails on Ubuntu 16.04

Follow by Email

In this article we will go through steps on how to install ruby on rails on Ubuntu 16.04.

Ruby on Rails is one of the most popular application stacks for developers looking to create sites and web apps. The Ruby programming language, combined with the Rails development framework, makes app development simple.

Update and install dependencies

First, we should update apt-get since this is the first time we will be using apt in this session. This will ensure that the local package cache is updated.

  • sudo apt-get update

Next, let’s install the dependencies required for rbenv and Ruby with apt-get:

  • apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev

Once we have all of the required system dependencies installed, we can move onto the installation of rbenv itself.

Install rbenv

Now we are ready to install rbenv. Let’s clone the rbenv repository from git. You should complete these steps from the user account from which you plan to run Ruby.

  • git clone ~/.rbenv

  • echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bashrc
  • echo ‘eval “$(rbenv init -)”‘ >> ~/.bashrc

You can check to see if rbenv was set up properly by using the type command, which will display more information about rbenv:

  • type rbenv

Your terminal window should output the following:

rbenv is a function
rbenv () 
    local command;
    if [ "$#" -gt 0 ]; then
    case "$command" in 
        rehash | shell)
            eval "$(rbenv "sh-$command" "[email protected]")"
            command rbenv "$command" "[email protected]"

In order to use the rbenv install command, which simplifies the installation process for new versions of Ruby.

Install Ruby

With the ruby-build rbenv plugin now installed, we can install whatever versions of Ruby that we may need through a simple command. First, let’s list all the available versions of Ruby:

  • rbenv install -l

The output of that command should be a long list of versions that you can choose to install.

We’ll now install a particular version of Ruby. It’s important to keep in mind that installing Ruby can be a lengthy process, so be prepared for the installation to take some time to complete.

As an example here, let’s install Ruby version 2.3.1, and once it’s done installing, we can set it as our default version with the global sub-command:

  • rbenv install 2.3.1
  • rbenv global 2.3.1

If you would like to install and use a different version, simply run the rbenv commands with a different version number, as in rbenv install 2.3.0 and rbenv global 2.3.0.

Verify that Ruby was properly installed by checking your version number:

  • ruby -v

If you installed version 2.3.1 of Ruby, your output to the above command should look something like this:

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

You now have at least one version of Ruby installed and have set your default Ruby version.

Install Rails

As the same user, you can install the most recent version of Rails with the gem install command:

  • gem install rails

If you would like to install a specific version of Rails, you can list the valid versions of Rails by doing a search, which will output a long list of possible versions. We can then install a specific version, such as4.2.7:

  • gem search ‘^rails$’ –all
  • gem install rails -v 4.2.7

rbenv works by creating a directory of shims, which point to the files used by the Ruby version that’s currently enabled. Through the rehash sub-command, rbenv maintains shims in that directory to match every Ruby command across every installed version of Ruby on your server. Whenever you install a new version of Ruby or a gem that provides commands, you should run:

  • rbenv rehash

Verify that Rails has been installed properly by printing its version, with this command:

  • rails -v

If it installed properly, you will see the version of Rails that was installed. We can now continue to set up our Ruby on Rails environment.


Take your time to comment on this article

Follow by Email

Add a Comment

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

Like the article? please consider sharing it. Thank you

Advertisment ad adsense adlogger