Understanding Rubygem's Load Errors

While rubygems is a great way of installing your packages without having yourself to dirty your hands, but if you installed your gems this way, it however does not mean that loading those newly installed gems is automatically.

It took me a while before I understood why my newly installed gems cannot be loaded through the ‘require’ statement, and giving me irksome messages like the ‘no such file to load’ error:

LoadError: no such file to load -- sequel
 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
 from (irb):1

That unhelpful message actually implies that you’re missing rubygems as a requirement. So make sure you load rubygems via 'require' before you load any other gems installed by it in your source file:

require 'rubygems'
# put all other requirements after this

The other way of permanently including rubygems is to export the -rubygems flag into your RUBYOPT environment variable. Different shells may vary, but here’s how you’ll do it in bash:

% export RUBYOPT=-rubygems

Do make sure you check if there are any existing flags in RUBYOPT first before overwriting it though!