How To Install Ruby on Rails with rbenv on Debian 7 (Wheezy)

Introduction

Ruby on Rails,based upon Ruby, is a web framework that is open source. As it is quite easy to build and ship an application, it is a very popular option used by startups. Ruby needs to be installed in order to begin using Ruby on Rails. Although you are most likely to wind up with Ruby’s older version because of the way of working ofDebian packaging system. Therefore, this tutorial will provide you with a safe method for utilizing most advanced versions of Ruby on Rails and Ruby.

Install rbenv

Some packages need to be installed in order to stop Debianfrom complaining about missing libraries or files. Debian packaging system will be utilized for that.

Firstly, we have to ensure that we are armed with all the advanced packages that can be deployed:

sudo apt-get update

Now, we will be installinggit package in order to utilizegit commands:

sudo apt-get install git-core

No installer is provided by rbenv, so we will have to utilize the source from Github. Hence, it needs to be cloned into our home directory.

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Debian utilizes a variable PATH in order to look upexecutables whenever a command is run. Therefore, path needs to be appended with rbenvexecutables in it. This needs to be done everytime on logging in as our user.Hence, we’ll be usingbashrcwhich will be run each time we try to login as a user:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

Another command needs to be added in our bashrc for shims[1] and auto completion for rbenv:

echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Your shell needs to be restarted (openinga new terminal tab will be sufficient). Run the command provided for checking if everything is running:

type rbenv

An output as given below will be obtained:

rbenv is a function

This is it. Rbenv has been installed successfully. But not everything is complete. For simplifying the installation of ruby, ruby-build, one of the rbenv plugins, needs to be installed by cloning it from Github:

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Because of the way of shims working, rbenv rehash needs to be run at all times during installation or uninstallation of gem. For preventing it, one morerbenv plugin can be utilized which will do it automaticallyfor us. As always, we will be cloning it for installation

git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

Install ruby

Now all things are ready for installation of our rbenv. Now, we will be installing a ruby. But prior to it, some requisite packages needs to be installed for ensuringseamless installation.

apt-get install build-essential libssl-dev libcurl4-openssl-dev libreadline-dev -y

We can utilize command given below for listing all versions of Ruby that are available for you to opt:

rbenv install --list

Version 2.1.0 has been utilized for this tutorial. For installing it, the command below needs to be run:

rbenv install 2.1.0 -k

-k will keep source of Ruby. In future, this will be helpful in building of other gems.

At present, we require to fix which version we intend to utilize every time ruby  command is run. Ensure that any directory is removed in your ~/.rbenv/sources  in case any problems are encountered for this command.

 

In order to fix it to be used globally, just run:

rbenv global 2.1.0

This is it, ruby 2.1.0 is now installed. This can be verified by running:

ruby -v

Something like below will be obtained (as per your version):

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]

Ruby on Rails Installation

For basic application creation, Ruby on Rails (RoR) offers a command. This command can be used for setting up gem directories, your directories and more. Prior to its running, it needs to be made sure that all packages are deployed.

RoR will be using sqlite as its database by default. For utilizing it without a single error,  sqlite packages are required for Debian:

sudo apt-get install sqlite3 libsqlite3-dev

JavaScript runtime[2] will also be required by RoR . However, a number of methods are there for doing this, but we will be using nodejs from Debian Backports[3] for installing it.

For using it, Debian Backports repositories need to be added:

Navigate to the file where your Debian repositories have been defined:

sudo nano /etc/apt/sources.list

Now the following lines need to be appended in the file:

deb http://ftp.us.debian.org/debian/ wheezy-backports main
deb-src http://ftp.us.debian.org/debian/ wheezy-backports main

Typically, ensure that all the packages list have been obtained by running this command:

sudo apt-get update

For installing nodejs, this command needs to be run:

sudo apt-get -t wheezy-backports install nodejs

Now deploy Ruby on Rails by using the command given:

gem install rails

Out First Ruby on Rails Application

Everything is now in place for creating our first application of RoR.  Create it by running this command (mynewapplication can be modified to anything you intend):

rails new mynewapplication

Required gems will be installed automatically by it. On finishing, go in its directory:

cd mynewapplication

Begin your application by running this command:

rails s

Start your browser and move onto this address:

http://your_ip_or_domain:3000

A Welcome aboard page will be seen. Click  on “About your application’s environment” and something as below will be visible.

Screenshot

Congratulations! Your first RoR application has been created and installed successfully.

KB Admin has written 28 articles

Leave a Reply