Including Ruby Gems in Scripts

Posted by nick.stielau on September 25, 2007

For quite a while, I was trying to write a ruby script to print some growl messages. I was having a hard time loading the growl code, using the "require 'ruby-growl'" syntax. I started digging around and looking at ruby's load path.

CODE:
  1. nicks-computer:~/Desktop/depot nick$ irb
  2. irb(main):001:0> puts $:
  3. /usr/local/lib/ruby/site_ruby/1.8
  4. /usr/local/lib/ruby/site_ruby/1.8/i686-darwin8.9.1
  5. /usr/local/lib/ruby/site_ruby
  6. /usr/local/lib/ruby/1.8
  7. /usr/local/lib/ruby/1.8/i686-darwin8.9.1
  8. .
  9. => nil

After a while, I got it working and left it as

RUBY:
  1. require '/usr/lib/ruby/gems/1.8/gems/ruby-growl-1.0.1/lib/ruby-growl.rb'

A couple months later I opened the script again, and laughed. Hahaha. Its as easy as

RUBY:
  1. require 'rubygems'
  2. require 'ruby-growl