2 min read

Rails 3.2 with Ruby 1.9.3 on Ubuntu Linux 12.04

 

The Ruby on Rails framework installation has changed a bit, so here a basic setup on Linux Ubuntu/Debian with the simplest steps as possibile.

Installation

First, install the basic ruby stuff, via apt-get. NB: everytime you use a C or C++ dependency you need the specific headers (example, to install "rmagick" the imagemagick wrapper you need "libmagickwand-dev", in general you could need some *-dev, if the mapping is not so obvious google is your friend).
The latest version of ruby (1.9.3) has been mapped to the package "ruby1.9.1" on Debian and Ubuntu 12.04

sudo apt-get install ruby1.9.1 ruby1.9.1-dev nodejs libsqlite3-dev g++

Now setup rubygems, the official package manager for the ruby land environment.

echo "gem: --no-ri --no-rdoc" > $HOME/.gemrc
sudo gem install rails thin

If you need or plan to manage multiple ruby versions you need also rvm or rbenv.

Example application

rails new myapp && cd myapp

The gems which aren’t project specific is better keep them system-wide so use the command “sudo gem” to install them.

Use the bundle command to keep your project dependencies update.

bundle install

A simple test app

rails g scaffold note title:string content:text
rails s # or thin start

and finally, go to http://localhost:3000/notes to check that everything is working correctly

Bundle install and the root password

If you don't want to type the root password for every new project a solution is to move the GEM paths in a directory where the user can write, otherwise a simple solution is to make that folders writable by the user.

sudo chown your_user /var/lib/gems/1.9.1 -Rv
sudo chown your_user /usr/local/bin -Rv

Troubleshooting

Errno::ENOMEM: Cannot allocate memory - sudo -p 'Enter your password to install the bundled RubyGems to your system: ' mv /home/yourserver/.bundler/tmp/3226/cache/uglifier-1.2.4.gem /var/lib/gems/1.9.1/cache/uglifier-1.2.4.gem

Probably you don’t have enough RAM, so you need to free your memory. Anyway you can run manually sudo -p 'Enter your password to install the bundled RubyGems to your system: ' mv /home/yourserver/.bundler/tmp/3226/cache/uglifier-1.2.4.gem /var/lib/gems/1.9.1/cache/uglifier-1.2.4.gem

WARN  Could not determine content-length of response body

It’s a Webrick problem, if You are annoyed by that install the Thin webserver

~/Deploy/myapp$ thin start                                                                                              ↵  
>> Using rack adapter
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

That's all for now