MarkUs Blog

MarkUs Developers Blog About Their Project

Archive for the ‘rubygems’ tag

Getting Started with Ruby on Rails

with 2 comments

Update: March 13, 2009

I’ve tried installing rails again from scratch, from a newly installed Ubuntu 8.10 and I got a “no ruby-full package” error when I tried to execute the install command sudo apt-get install ruby-full rubygems build-essential

If this happens, you can enable external package repositories by going to System -> Administration -> Software Sources.  Then you can go to Third-Party Software tab and select both sources (‘http://archive.canonical.com/ubuntu intrepid’ as of Ubuntu 8.10) and do a sudo apt-get update after on the command line. Once update is done, installing ruby-full package should now work.

———-

Here, I outline the steps I took to get started with Ruby on Rails development on Ubuntu 8.04

1.  Install ruby

To install ruby (1.8.6) and rubygems, simply type:

sudo apt-get install ruby-full rubygems build-essential

2.  Update gem

When installing rails, make sure that you let gems manage it rather than apt-get, otherwise, “gem and apt-get will start fighting like Spock and Captain Kirk in Amok Time.”  Thus, we need to make sure rubygems is updated using the command sudo gem update (for gems 0.9.4)

Now, you might or might not encounter this but when I did this on Ubuntu 8.04, I got the following error:

Updating RubyGems...
Bulk updating Gem source index for: http://gems.rubyforge.org
Attempting remote update of rubygems-update
ERROR:  While executing gem ... (Gem::GemNotFoundException)
Could not find rubygems-update (> 0) in any repository

Asking the all-knowing Google lead me to this fix.  You apparently need to remove the local source_cache file found in the GEM PATH.  You can get this path by running the command gem env, giving you this result:

$ gem env
RubyGems Environment:
- VERSION: 0.9.4 (0.9.4)
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- GEM PATH:
- /var/lib/gems/1.8
- REMOTE SOURCES:
- http://gems.rubyforge.org

Once you get your GEM PATH (in my case /var/lib/gems/1.8), then you need to remove the local cache by typing:

sudo rm -rf /var/lib/gems/1.8/source_cache

and continue to update gem.

3. Install rails

Now that you have gem updated, you can then confidently install rails and its dependencies by typing:

sudo gem install rails --include-dependencies

Make sure that you also add the gem bin path to your path. If you’re using bash, then add the following line to your .bashrc, replacing <GEM_PATH> with your gem path found by typing gem env (don’t forget to restart terminal):

export PATH=$PATH:<GEM_PATH>/bin

Verify installation by typing, rails -v and get the following (or similar) response:
Rails 2.1.0

4. Install a Database

Since I already have a MySQL server, I wanted to work with it instead of the default SQLite database for Rails.  This means installing the MySQL driver for rails and typing the command:

sudo apt-get install libmysql-ruby mysql-server

You can leave out the mysql-server if you already have the MySQL server installed.

5. Install a Ruby on Rails server

Reading some of the posts, I found that there are two most popular servers to use for RoR apps: Mongrel and Webrick.  Webrick I believe comes with the rails installation, but there’s huge evidence that Mongrel might be better than Webrick.  Using the steps found here, I installed Mongrel on Ubuntu by typing:

sudo gem install mongrel --include-dependencies

You might be given options to select versions.  In my case, I just selected the latest version of mongrel (1.1.5) and fastthread (1.0.1) for ruby.

6. Create sample application

To make sure everything works, we can create a sample rails application.  Start by typing rails cookbook -d mysql if you’re using MySQL, otherwise leave the -d flag out to use SQLite instead.  The database configuration assumes that you have a MySQL user called root, with the password disabled.  If this is not the case, then you might need to edit the config file cookbook/config/database.yml and make appropriate changes under development. To make sure the database also works, we need to create a sample application that uses our database. To do this, just type in console under the cookbook directory:

ruby script/generate scaffold recipe title:string description:text category:string

mysql -u root --password=<your_password> -e "CREATE DATABASE cookbook_development"

rake db:migrate

Once that’s done, just execute mongrel_rails start under the cookbook directory, fire up your browser to http://localhost:3000/recipes (note that it’s plural) and you should see your cookbook web application staring back at you.

Note: If you get a CGI::Session::CookieStore::TamperedWithCookie error when hitting the recipes page, just hit browser refresh and that should be fixed (not sure why it does that sometimes).

7. Find a good Ruby on Rails IDE (no, this is not optional)

Now the hard part of all this is getting settled into a familiar development environment.  There are some good discussions out there on what people use as RoR IDEs.  Since I don’t have a week to throw away learning emacs, I’ve decided to start with something familiar, Eclipse.  The only decent Eclipse-based IDE out there is RadRails, but installing the standalone verion, I found that it was too alpha for me at this stage (crashes frequently, unresponsive, and can’t find my rails installation).  So I’m settling right now with the Rails plug-in for NetBeans and so far it’s been good for me, except for the occasional GUI lag that I’m getting. I’ve also heard good things about jEdit, but without the debugger support, it’s not technically an IDE for me.

Written by Geofrey

July 17th, 2008 at 4:32 pm

Posted in OLM on Rails

Tagged with , , , ,