# Is there any relevant difference between require and require

**URL:** <https://www.ruby-forum.com/t/is-there-any-relevant-difference-between-require-and-require/49296>\
**Category:** Ruby\
**Created:** [December 2, 2005, 8:15am UTC](https://www.ruby-forum.com/t/is-there-any-relevant-difference-between-require-and-require/49296 "2005-12-02T08:15:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lasso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9d8465/32.png) [@lasso](https://www.ruby-forum.com/u/lasso)\
**Post date:** [December 2, 2005, 8:15am UTC](https://www.ruby-forum.com/t/is-there-any-relevant-difference-between-require-and-require/49296/1 "2005-12-02T08:15:21Z")

</div>

Hi all!

When using Rubygems, is there any _relevant_ difference between using  
require and require\_gem (aside from the versioning possibilities)?  
According to the docs require searches the standard library first. Is  
this true for require\_gem too, or does that method only search the gem  
repository? Is is faster?

Example:  
require ‘rubygems’

# Is any of the two methods below “better” in any way?

require ‘sqlite3’

# Or

require\_gem ‘sqlite3-ruby’

Kindly

/Lars

---

<div class="post-metadata">

**Author:** ![lasso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9d8465/32.png) [@lasso](https://www.ruby-forum.com/u/lasso)\
**Post date:** [December 2, 2005, 3:29pm UTC](https://www.ruby-forum.com/t/is-there-any-relevant-difference-between-require-and-require/49296/2 "2005-12-02T15:29:13Z")

</div>

lasso wrote:

> Hi all!
> 
> When using Rubygems, is there any _relevant_ difference between using  
> require and require\_gem (aside from the versioning possibilities)?  
> According to the docs require searches the standard library first. Is  
> this true for require\_gem too, or does that method only search the gem  
> repository? Is is faster?

There is a fundamental difference between require and require\_gem:

(1) require specifies a file name and loads that file into your ruby  
session.

(2) require\_gem specifies a gem name and puts the files in that gem on  
the search path so that later requires will be able to find the gems  
file (we call this process “gem activation”). Sometimes require\_gem  
will auto-require the “main” file of a gem (if the author if the gem  
specified an main file).

RubyGems is smart enough that it can generally figure out what gem needs  
to be activated via normal require statements, so the require\_gem is  
almost never needed. In fact, I would recommend only using the  
require\_gem statement if you need a particular version a gem package (by  
default, RubyGems will select the latest version for you).

I’ll repeat: Never use “require\_gem” without a version specification.  
Prefer to use a plain “require” instead.

Future versions of RubyGems will rename “require\_gem” (probably to  
“activate\_gem”) and have it drop the auto-require step. This should  
lessen the confusion between the normal require and RubyGems activation  
process.

– Jim W.

---

<div class="post-metadata">

**Author:** ![lasso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9d8465/32.png) [@lasso](https://www.ruby-forum.com/u/lasso)\
**Post date:** [December 2, 2005, 3:31pm UTC](https://www.ruby-forum.com/t/is-there-any-relevant-difference-between-require-and-require/49296/3 "2005-12-02T15:31:08Z")

</div>

On 12/2/05, Lars O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> require ‘sqlite3’
> 
> # Or
> 
> require\_gem ‘sqlite3-ruby’

Yes. require\_gem, at least for some gems, and _definitely_ for future  
versions of PDF::Writer and other packages that I write will only  
require the gem. It will not autorequire the core functionality as it  
does now.

-austin
