Ruby on Rails Installation

We will set up Ruby on Rails in Ubuntu 14.04 operating system.

There are three methods to install Ruby:

  • Using rbenv (recommended)
  • Using rvm
  • From source

We will install using rbenv as it is the most recommended way.

First we will install some dependencies for Ruby:

sudo apt-get update  
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev   

libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev   

libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs

Install rbenv

Installing rbenv is a simple two way process. First rbenv will be installed and then ruby-build.

Follow the following commands:

cd  

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

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

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

exec $SHELL
git clone git://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build  

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

exec $SHELL

The above command will install rbenv in your home directory and will set the appropriate environment variables.


Install Ruby

Install Ruby using following commands:

  1. rbenv install -v 2.2.3  
  2. rbenv global 2.2.3  

To disable Rubygems which generate local documentation for each gem that you install, use following command:

echo "gem: --no-document" > ~/.gemrc  

Now you need to install bundler gem to manage application dependencies with following command.

gem install bundler  

Install Rails

Install Rails using following command,

gem install rails  

You can specify the version of Rails which you want to install using -v option in the above command.

Now we will run rehash sub-command. This will install shims for all Ruby executables known to rbenv, which allow you to use executables.

rbenv rehash  

To verify the installed Rails version, use the following command.

rails -v  
Ruby On rails installation 1

Install JavaScript Runtime

Some Rails features like Asset Pipeline, depends on JavaScript runtime. To get this functionality, we need to install Node.js.

sudo add-apt-repository ppa:chris-lea/node.js  

  1. sudo apt-get update  
  2. sudo apt-get install nodejs  

Now you have successfully installed Ruby on Rails on your system.

Install Database

Rails default database is Sqlite3. If you want to use some other database due to any reason, then you need to install it.

Here, we will install MySQL server as our database.

sudo apt-get install mysql-server mysql-client libmysqlclient-dev  

After this, install mysql2 gem, with following command.

gem install mysql2  

Now you can easily use MySQL with Rails in your system.


Comments

Leave a Reply

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