How to install ruby on rails on Ubuntu 16.04

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2016/08/install-ruby-rails-ubuntu-16-04/

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 https://github.com/rbenv/rbenv.git ~/.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:

Output
<code>rbenv is a function
rbenv () 
{ 
    local command;
    command="$1";
    if [ "$#" -gt 0 ]; then
        shift;
    fi;
    case "$command" in 
        rehash | shell)
            eval "$(rbenv "sh-$command" "$@")"
        ;;
        *)
            command rbenv "$command" "$@"
        ;;
    esac
}
</code>

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:

Output
<code>ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
</code>

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
Facebook0
Facebook
Google+
https://codingsec.net/2016/08/install-ruby-rails-ubuntu-16-04/

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