# What is the point of require\_gem in Ruby 1.8.2?

**URL:** <https://www.ruby-forum.com/t/what-is-the-point-of-require-gem-in-ruby-1-8-2/55769>\
**Category:** Ruby\
**Created:** [March 23, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/what-is-the-point-of-require-gem-in-ruby-1-8-2/55769 "2006-03-23T18:51:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/what-is-the-point-of-require-gem-in-ruby-1-8-2/55769/1 "2006-03-23T18:51:03Z")

</div>

I just went through this mess over the last few hours…

[http://www.ruby-forum.com/topic/59185](http://www.ruby-forum.com/topic/59185)

If I do:

require\_gem ‘gemname’, ‘\>= version’

I discovered that require\_gem doesn’t actually do the “require” call on  
the 1st argument.

So what’s the point of require\_gem then?

It did manage to confuse the heck out of me, so I guess it does  
something :)…

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 7:45pm UTC](https://www.ruby-forum.com/t/what-is-the-point-of-require-gem-in-ruby-1-8-2/55769/2 "2006-03-23T19:45:26Z")

</div>

Wes G. wrote:

> I just went through this mess over the last few hours…
> 
> [Problem seeing classes in rubygem - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/59185)
> 
> If I do:
> 
> require\_gem ‘gemname’, ‘\>= version’
> 
> I discovered that require\_gem doesn’t actually do the “require” call on  
> the 1st argument.

That’s because the first argument is the name of the Gem to be  
activated, not the name of a file to be required.

However, many gems have the same name as their main require file, so  
there is a lot of confusion. Also some gems have an ‘autorequire’ flag  
set that /will/ do a require on the main file.

And to futher the confussion, the command name ‘require\_gem’ was poorly  
selected. Future versions of RubyGems will provide a better named  
command for this operation.

> So what’s the point of require\_gem then?

If you have multiple versions of a gem installed, the require\_gem  
command specifies what version of the gem you are willing to use. If  
you don’t care what version will be used, and just want the latest  
version of whatever is installed, then there is no reason to even bother  
with the require\_gem command.

–  
– Jim W.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/what-is-the-point-of-require-gem-in-ruby-1-8-2/55769/3 "2006-03-23T21:26:11Z")

</div>

Jim,

So I think the question still stands. Is require\_gem only do the  
version checking?

What does it mean to “activate” a Gem?

Wes

Jim W. wrote:

> Wes G. wrote:
> 
> > I just went through this mess over the last few hours…
> > 
> > [Problem seeing classes in rubygem - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/59185)
> > 
> > If I do:
> > 
> > require\_gem ‘gemname’, ‘\>= version’
> > 
> > I discovered that require\_gem doesn’t actually do the “require” call on  
> > the 1st argument.
> 
> That’s because the first argument is the name of the Gem to be  
> activated, not the name of a file to be required.
> 
> However, many gems have the same name as their main require file, so  
> there is a lot of confusion. Also some gems have an ‘autorequire’ flag  
> set that /will/ do a require on the main file.
> 
> And to futher the confussion, the command name ‘require\_gem’ was poorly  
> selected. Future versions of RubyGems will provide a better named  
> command for this operation.
> 
> > So what’s the point of require\_gem then?
> 
> If you have multiple versions of a gem installed, the require\_gem  
> command specifies what version of the gem you are willing to use. If  
> you don’t care what version will be used, and just want the latest  
> version of whatever is installed, then there is no reason to even bother  
> with the require\_gem command.
> 
> –  
> – Jim W.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 24, 2006, 12:23am UTC](https://www.ruby-forum.com/t/what-is-the-point-of-require-gem-in-ruby-1-8-2/55769/4 "2006-03-24T00:23:24Z")

</div>

Wes G. wrote:

> Jim,
> 
> So I think the question still stands. Is require\_gem only do the  
> version checking?

The require\_gem does two basic functions:

(1) Activates a gem with an appropriate version number (see below for  
more on “activate”)

(2) Auto requires the autorequire file if the gem has specified one.

After much experience with gems, the RubyGems team has come to the  
conclusion that the autorequire step causes more trouble than its worth.  
The require\_gem command will be probably be deprecated in the future and  
be replaced with a command that only does the activation step.  
(‘activate\_gem’ will probably be then name of this new command, although  
no promises there).

Require\_gem is only needed if you wish to assert which versions of a gem  
you are willing to accept. If you don’t care, it is better to not use  
it.

> What does it mean to “activate” a Gem?

Gems are not stored in a place where Ruby can normally find them. To  
activate a gem means to manipulate Ruby’s search path so that the gem  
may be found by a require statement. Only one version of any given gem  
can be activated at a time.

Today, Gems monitors all require requests given to Ruby. If a require  
fails to load a file, then Gems will check its repository to see if  
there is a file that satisfies the require statement. If so, RubyGems  
will activate the latest version of the gem that provides that file and  
will retry the require.

Since RubyGems now automatically handles normal require statements  
semi-intelligently, the autorequire feature of the original require\_gem  
is more of a hinderence than a help[1].

–  
– Jim W.

[1] For example, if a gem has an autorequire file, then that autorequire  
file will be loaded by the activation step. If a user does a normal  
“require ‘xyz’” that triggers an activation, when the require is retried  
the file will be already ‘autorequired’. There’s is no harm in that  
except that the result of the user’s require statement returns false  
(since the file will autoloaded durning activate), and returning false  
confuses a lot of people. I hope this footnote didn’t ramble too much.
