tags:

views:

56

answers:

1

This is related to this question:

http://stackoverflow.com/questions/3179797/how-to-use-rubytorrent-or-other-gems

I thought RubyGems is a package manager, similar to apt-get on Ubuntu...

So when do we need to require 'rubygems' in our code?

+3  A: 

Use require 'rubygems' when you are using a gem that you installed with Rubygems. The reason is that Ruby uses Rubygems to determine the path of the gem that Rubygems installed. (is unable to locate the gem you want to use)

Alternatively, you can pass the -rubygems flag when you invoke your script, or set export RUBYOPT=rubygems in your profile (~/.bashrc or ~/.bash_profile or ~/.profile) which is basically the same as the flag, except it is implicit.

On 1.9, rubygems is required implicilty, and you shouldn't have to do that.

Here are some docs about it http://docs.rubygems.org/read/chapter/3

Note: Some have built solutions (zozo and faster_rubygems) to avoid Rubygems overhead http://www.ruby-forum.com/topic/212463

Joshua Cheek