Lubos Rendek

The only solution is determination.

Ruby on Rails 3 Tutorial 2nd Edition - Linux Debian 7 Wheezy Environment Setup

| Comments

In case you have decided to learn Ruby on Rails with book:

Ruby on Rails Tutorial
Learn Web Development with Rails

Second Edition by Michael Hartl

congratulate you to a choice. The book is written with care and precision however, the initial setup is rather os-agnostic. Therefore, here is my attempt to setup Ruby on Rails environment according to the exact book specifications. There is only one exception that is Ruby Version Manager (RVM). Instead of RVM I chose rbenv and rbenv-gemset.

First as a root user install all prerequisite packages:

1
# apt-get install rbenv ruby1.9.1-dev git libsqlite3-dev

Set ruby environment to by set after each login:

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

Add available ruby alternatives to rbenv manager:

1
2
3
$ rbenv alternatives
         Added 1.8.7-debian
         Added 1.9.3-debian

To set ruby version to 1.9.3 execute following commands:

1
2
3
$ rbenv global 1.9.3-debian
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

Next suppress the ri and rdoc documentation by:

1
2
$ echo 'install: --no-rdoc --no-ri' > .gemrc
$ echo 'update: --no-rdoc --no-ri' >> .gemrc

At this point we are ready to create a gem set to be used with this tutorial. As specified by the book the gemset will be called: rails3tutorial2ndEd. First we need to fetch rbenv-gemset and install. The following 2 commands will do the trick:

1
2
$ mkdir ~/.rbenv/plugins; cd $_
$ git clone git://github.com/jf/rbenv-gemset.git; cd

Once ready we can create new gemset rails3tutorial2ndEd to be bundled with ruby version 1.9.3.

1
$ rbenv gemset create 1.9.3-debian rails3tutorial2ndEd

Activate new gemset:

1
2
$ echo rails3tutorial2ndEd > .rbenv-gemsets
$ eval "$( rbenv init -)"

At this point it would be wise to check our gem environment:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/lubos/.rbenv/versions/1.9.3-debian/gemsets/rails3tutorial2ndEd
  - RUBY EXECUTABLE: /usr/bin/ruby1.9.1
  - EXECUTABLE DIRECTORY: /home/lubos/.rbenv/versions/1.9.3-debian/gemsets/rails3tutorial2ndEd/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/lubos/.rbenv/versions/1.9.3-debian/gemsets/rails3tutorial2ndEd
     - /home/lubos/.rbenv/versions/1.9.3-debian/gemsets/global
     - /var/lib/gems/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-rdoc --no-ri"
     - "update" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/

Pay special attention to:

  • EXECUTABLE DIRECTORY
  • GEM PATHS

At this point we are ready to install rails version 3.2.3

1
2
3
$ gem install rails -v 3.2.3
31 gems installed
$ eval "$( rbenv init -)"

Check rails version:

1
2
$ rails -v
Rails 3.2.3

Lets start first project:

1
2
3
4
5
$ mkdir rails_project; cd $_
$ rails new first_app
Installing uglifier (2.3.2) 
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

As suggested by Michael’s book edit your projects Gemifile as below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
source 'https://rubygems.org'

gem 'rails', '3.2.3'


group :development do
        gem 'sqlite3', '1.3.5'
end


group :assets do
  gem 'sass-rails',   '~> 3.2.4'
  gem 'coffee-rails', '~> 3.2.2'
  gem 'uglifier', '>= 1.2.3'
end

gem 'jquery-rails', '~> 2.0.0'

Update your bundle to appropriate gem versions:

1
2
3
4
$ cd first_app/
$ bundle install
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

Feel free to start rails server:

1
$ rails server

an navigate your browser to: http://localhost:3000

In case that you get an error message complaining about the lack of JavaScript runtime:

1
execjs-2.0.2/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

then you might want to install node.js. Feel free to use my Debian node_0.10.22-1_amd64.deb 64 bit build.

1
# dpkg -i node_0.10.22-1_amd64.deb

Comments