Installing rails 3.1 and ruby 1.9.2-p180 using rvm and unicorn setup

Install rvm

Open your .bashrc file.
And replace the following line
[ -z “$PS1” ] && return
with
if [[ -n “$PS1” ]]; then
Now add this to the last line of the file
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi

fi
This loads RVM into a shell session.

If already have rvm then
Update rvm

$ rvm get latest

if this shows error like ‘downloaded does not match it’s md5 checksum’

then run

$ rvm get head
$ rvm reload
$ rvm get latest

For ruby 1.9.2 we want the packages it lists under the MRI & ree section. Let’s install those now.

$ sudo aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline-dev libxml2-dev git-core subversion autoconf

Setting up Ruby

Do rvm list known to know all ‘Ruby implementation made available through RVM’

$ rvm list known

Then install latest stable release of ruby

$ rvm install 1.9.2

You can see the ruby versions installed and currently using ruby version by

$ rvm list rubies

To list default ruby

$ rvm list default

You can change it by

$ rvm use ruby-1.9.2-p180

for default : rvm –default 1.9.2-p180

Using Gemsets

Install rails stable release and then rails 3.1
Start by creating our gemsets

$ rvm gemset create rails307 rails31

See available gem sets by

$ rvm gemset list

If any confusion with rails31 gemset delete it

$ rvm gemset delete rails31

And create rails31rc

$ rvm gemset create rails31rc

As a best practice, remember to always use one gemset per project*.

Installing Rails

Now we have multiple gem set installed. Now set the different gem set for ruby versions.

$ rvm use 1.9.2-p180@rails307

Install Rails 3.0.7

$ gem install rails [-v 3.0.7] [–no-rdoc]

Select the gemset for Rails 3.1

$ rvm use 1.9.2-p180@rails31rc

for default $ rvm use 1.9.2-p180@rails31rc –default

Install Rails 3.1

$ gem install rails -v “>=3.1.0rc”

if not found

$ gem install rails -v “>=3.1.0.rc4”

rvmrc file

Switching from one project to another, from a client to a personal project, from testing the release candidate to developing using the latest stable version, always having to manually switch from using a gemset to another can impact productivity. The project .rvmrc files can increase the development speed by setting up our project’s ruby environment when we switch to the project root directory.

The rule of thumb here is to use a .rvmrc file for each project, for both development and deployment.*

.rvmrc file :

rvm –rvmrc use 1.9.2-p180@rails31rc

if you go to your app folder ‘$ cd myapp’ then you can see like





There are three types of .rvmrc files
1) system : on /etc/rvmrc
2) user : $HOME/.rvmrc
3) Project : .rvmrc

Create a new rails App

$ rails new myapp

with mysql as database

$ rails new myapp -d mysql
$ rails server -p4000

If u get error like

“”” home/user/.rvm/gems/ruby-1.9.2-p180@rails31rc4/gems/execjs-1.1.2/lib/
execjs/runtimes.rb:43:in `autodetect’: Could not find a JavaScript
runtime. See https://github.com/sstephenson/execjs for a list of
available runtimes. (ExecJS::RuntimeUnavailable) “””

Then you need a javascript engine to run your code…

try installing rubyracer (Embeds the V8 Javascript interpreter into Ruby.)

in your Gemfile add

gem ‘therubyracer’
and do bundle install

Unicorn Installation

$ rvm use default # Just to make sure
$ gem install unicorn

Start unicorn server

$ unicorn_rails

Advertisements

Author: Abhilash

Hi, this is Abhilash - Senior Programmer Analyst at CoMakeIT, specialised on web programming. Mainly working on Ruby On Rails platform since 2010.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s