Introduction

Here are a few notes I took while trying to install Ruby 1.9.2, Rails 3, on a Ubuntu 10.10 Maverick system. The Debian style packaging for Ruby doesn’t sound like a good idea to me in a world where most of the gems are hosted on github and such, so I tried to use only the Ruby interpreter package from Ubuntu (1.9.2-p0).

This should also work on a Debian Squeeze system.

Installing Ruby 1.9.2-p0

Why using Ruby from APT when we plan to install everything else by hand? Well because a lot of packages are depending upon the ruby package (vim-scripts, for example), so we will most likely overwrite any manual installation sooner or later. I’d rather avoid that situation and keep using APT’s Ruby package.

We first need to install Ruby itself. We don’t really care if Ruby 1.8.7 is already installed on the same machine, everything should still work.

$ sudo apt-get install ruby1.9.1 ruby1.9.1-dev build-essential

We install build-essential even if its not entirely required yet: most of the common gems need to build native extensions.

If /usr/bin/ruby exists, ensure we have the right symlink to Ruby 1.9:

$ cd /usr/bin
$ sudo rm ruby
$ sudo ln -s ruby1.9.1 ruby

Installing RubyGems

Ensure that the RubyGems package isn’t installed:

$ sudo apt-get remove --purge rubygems

Grab the official version of RubyGems at http://rubygems.org/pages/download and run:

$ sudo ruby setup.rb

Again, we need to ensure that we have the correct symlink, so if /usr/bin/rubygems exists do:

$ cd /usr/bin
$ sudo rm gem
$ sudo ln -s gem1.9.1 gem

Everything should be installed and working now.

This installation should stay compatible with any upgrade of the system as long as you don’t install RubyGems from APT. You can ensure it won’t ever be installed nor upgraded by creating the /etc/apt/preferences.d/rubygems file and copying the following snippet:

Package: rubygems
Pin: version *
Pin-Priority: -100

Installing Ruby On Rails 3

This is the easier part:

$ sudo gem install rails

I strongly advise to install bundler alongside with Rails, as it became the standard way to handle your gems inside a Rails project:

$ sudo gem install bundler

Here goes for the base setup.

The database adapters

Most people will probably want to install both sqlite3 and mysql gems, but be careful: they need the development headers for the native extensions to compile.

$ sudo apt-get install libsqlite3-dev libmysqld-dev

Add them to your Gemfile:

group :development do
  gem "sqlite3-ruby", :require => "sqlite3"
end
group :production do
  gem "mysql2"
end

Then we’ll use bundler to setup everything:

$ bundle install

Those 2 gems are just an example on how you can setup your project dependencies. Most experienced developers will choose the database back-end of their choice: PostgreSQL, MongoDB (via MongoID), etc.

Conclusion

At this point you should have everything running smoothly.

Those of you doing Test Driven Development will probably want to install RSpec:

$ sudo gem install rspec rspec-rails

 

, , , , , ,
Trackback

3 comments untill now

  1. [...] the rest here: Installing Ruby On Rails 3.0.6 on Ubuntu 10.10 Maverick | devquotes, < a-few-notes, few-notes, maverick, Rails, took-while, ubuntu > « Cape Coral man [...]

  2. Hi, you really should check out RVM – it will easily allow you to run multiple ruby versions and different sets of gems without any hassle. http:://rvm.beginrescueend.com

  3. Hi,

    While RVM is clearly the best alternative for developers, it is not a sane way to install a production system IMHO.
    The base system should always be maintained through the package manager in order to keep up-to-date regarding security fixes while allowing easy administration.

Add your comment now