I recently started learning Ruby (mostly to flesh out my programming knowledge) and since one of the main self-detected shortcomings in my programming knowledge and skillset is web frameworks and web programming, I decided to give Ruby on Rails a shot. This post will describe the first steps needed to begin using Ruby, Ruby on Rails, and their entourage. I’m running Ubuntu 9.04 Jaunty Jackelope, but there are many guides out there to get you up and running. It will also cover some basic tips for using RubyGems and other related topics to get you going faster. Thanks to friend and co-worker Trevor Rosen for ample (cough, truculent, cough) encouragement, information, and assistance in this bauble-strewn journey.
First install Ruby and a few related items:
1
| sudo apt-get install ruby rdoc irb |
RDoc allows you to generate HTML API presentations from Ruby code. irb is the interactive Ruby prompt, great for trying out quick ideas.
Next you need to install RubyGems. RubyGems is the Ruby packaging system, as easy_install is to Python and apt-get is to Ubuntu. It’s a lovely package handling system. While I use and love setup_tools, it does have its shortcomings. RubyGems actually allows you to uninstall packages! Sounds simple enough, but easy_install users know this is a continual pain. RubyGems also allows much better searching and provides more information about potential packages.
I don’t recommend installing this from the Ubuntu repos. I ran into some odd problems, while the latest from RubyForge worked fine. If you do get it from the repo, be sure to install “rubygems”, not “gem” (Graphics Environment for Multimedia – PureData library)! To install from source, get the latest stable version from here on RubyForge, then:
1 2 3 4
| tar xzvf rubygems-VERSION.tgz
cd rubygems-VERSION/
sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem |
That last step is needed since the setup script doesn’t make its own symlink. This can make for wretched confusion… Here are some basic RubyGems commands and example output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| # View available commands
> gem help commands
GEM commands are:
...All the commands and descriptions thereof.
# Search for a gem by name:
> gem query --remote --name-matches flickr
*** REMOTE GEMS ***
flickr (1.0.2)
...Many more...
# Install a gem:
> sudo gem install --remote flickr
Successfully installed flickr-1.0.2
1 gem installed
# Get information on an installed gem:
> sudo gem specification flickr
--- !ruby/object:Gem::Specification
name: flickr
version: !ruby/object:Gem::Version
version: 1.0.2
...Lots more...
# Remove a gem:
> sudo gem uninstall flickr
Successfully uninstalled flickr-1.0.2 |
Consider adding a few Bash aliases for faster access to the basic commands:
1 2 3 4 5 6 7 8 9 10
| # Look for gems with "gquery name":
alias gquery="gem query --remote --name-matches"
# Install new gems with "ginst name":
alias ginst="sudo gem install"
# Get information on gems with "ginfo name":
alias ginfo="sudo gem specification"
# Remove gems with "gdel name":
alias gdel="sudo gem uninstall"
# Update gems:
alias gupdate="sudo gem update" |
Next install Rails and its merry band:

This will install Rails, its library dependencies, rake, etc. I first installed Rails via apt-get, but ran into a small issue.
Next, to get the general sense of creating a Rails app, I recommend starting off with The Original Ruby on Rails Screencasts by Sam Stephenson and David Hansson on ShowMeDo. These are by no means comprehensive guides, but they illustrate doing some basic things with Rails, and end up with some pretty nice apps in a few minutes. You’ll be hard pressed to follow along yourself, depending on how many hours of Doom you played as a child.
To really start to grasp things, check out the Getting Started guide on the RailsGuides site. This goes through each step from nothing to a working Rails app. As you proceed, you might want additional information on various technical details. Look no further than the Rails Searchable API site. You can browse this online or download it locally. It provides a decent looking (finally for an HTML API: readable) and useable API reference for Rails. The search is amazing, and they’ve done a great job compressing a lot of information into a relatively small amount of space.
Once you begin looking for information on how to accomplish various discrete tasks, check out Railscasts. These assume some Rails knowledge, but are decent simple guides to how to add features like reliable authentication, avoiding SQL injection, generating PDFs, and a lot more (160 so far!).
I hope to post more on Ruby and Ruby on Rails as I learn and play around with them. If you are new to Ruby, check out this page. I came across it after I started going through a few tutorials, and find it amply summarizes most of the features I started to love at first blush.