Sunday, April 22, 2007

Installation of Ruby and Ruby on Rails in BOSS

Update your sources.list with the boss repository

$ vi /etc/apt/sources.list add the following line

deb http://bosslinux.in/boss tarang main non-free contrib

Save the file and execute

$ apt-get update

Install Rails


1. Install ruby

First, you'll need Ruby.

$ apt-get install irb1.8 libreadline-ruby1.8 libruby libruby1.8 rdoc1.8 ruby ruby1.8 ruby1.8-dev

2. Install gems

Gems is a package manager. It is to Ruby what CPAN is to Perl or PEAR is to PHP. You will use it a lot to install Ruby extensions - or in this case, install Rails with all the necessary dependencies. Go to the RubyGems website on RubyForge and download the latest version:

cd /usr/local/src
wget http://rubyforge.org/frs/download.php/5207/rubygems-x.x.xx.tgz
tar zxf rubygems-x.x.xx.tgz
cd rubygems-x.x.xx
ruby setup.rb

Note that this will install RubyGems to /usr, which is convenient, but theoretically wrong. I personally feel that this is ok, since RubyGems does not exist as a Debian package and it would otherwise require some effort ensuring that the libraries are found. If you insist on installing RubyGems to /usr/local, read the Installing RubyGems under /usr/local guide on the Rails Wiki.
You should now have a gem command. Check with which gem that it is available on your system.

3. Install rails using gems

Now install Rails.

gem install rails --include-dependencies

You should now have a rails command. It is used to create new Rails applications. Check with which rails that it is on your system.

4. Install database bindings for ruby

Your Rails applications are going to require a database. I suggest you to install support for SQLite3 and MySQL, as the former is very useful for testing purposes or creating ad-hoc databases, and the latter is what you are probably going to use in a production environment.
Two steps are required to make the database bindings work: First, the header files have to be installed (these are the packages that end in -dev), then we are installing the Ruby bindings for the particular databases. The header files are required because the Ruby bindings contain C code to which has to be compiled first.

For MySQL:

apt-get install libmysqlclient14-dev
gem install mysql

For SQLite3:

apt-get install sqlite3 libsqlite3-dev
gem install sqlite3-ruby

For the installation, you will be presented with a list of versions. Pick the highest version for (ruby). In this case, this would be choice number 2. Don't worry about installing the wrong version - gem can install multiple versions in parallel.
Select which gem to install for your platform (i386-linux)

1. mysql 2.7.1 (mswin32)
2. mysql 2.7 (ruby)
3. mysql 2.6 (ruby)
4. mysql 2.5.1 (ruby)
5. Cancel installation

Troubleshooting

Obviously, things can go wrong.

"extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)"

This probably means that you forgot to install the ruby1.8-dev package. Just do an apt-get install ruby1.8-dev to fix this.

"Could not create Makefile due to some reason [..] Check the mkmf.log file for more details. [..]"

You should do what the error message tells you: check the mkmf.log! Search for this file using find /usr/lib/ruby/gems/1.8/gems/ -name mkmf.log. Usually, this error message appears because you forgot to install the -dev package for the extension you were trying to install. So if you wanted to install the mysql gem, you probably forgot to install the libmysqlclient14-dev first. Do an apt-cache search | grep dev to find the appropriate packages.

"installation or configuration problem: C compiler cannot create executables."
Make sure you have a compiler installed. Also, an important package that is often forgotten is libc6-dev. It contains the header files for the GNU LIBC, which is required by about every program out there.

apt-get install gcc make libc6-dev

And if you want to be sure:

apt-get install g++ automake autoconf