Ruby gems in stand-alone ruby scripts

You should be able to simply require it directly in recent versions of Ruby.

# optional, also allows you to specify version
gem 'chronic', '~>0.6'

# just require and use it
require 'chronic'
puts Chronic::VERSION  # yields "0.6.7" for me

If you are still on Ruby 1.8 (which does not require RubyGems by default), you will have to explicitly put this line above your attempt to load the gem:

require 'rubygems'

Alternatively, you can invoke the Ruby interpreter with the flag -rubygems which will have the same effect.

See also:

  • http://docs.rubygems.org/read/chapter/3#page70
  • http://docs.rubygems.org/read/chapter/4

Leave a Comment