# Odd requirement behavior between two environments

**URL:** <https://www.ruby-forum.com/t/odd-requirement-behavior-between-two-environments/109557>\
**Category:** Ruby\
**Created:** [July 16, 2007, 8:50pm UTC](https://www.ruby-forum.com/t/odd-requirement-behavior-between-two-environments/109557 "2007-07-16T20:50:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [July 16, 2007, 8:50pm UTC](https://www.ruby-forum.com/t/odd-requirement-behavior-between-two-environments/109557/1 "2007-07-16T20:50:56Z")

</div>

I’m setting up a Ruby project on a new development machine and have run  
into  
some trouble getting my unit tests to run. Can any one suggest what the  
vital difference between these two machines might be, or what is causing  
the  
error?

Esentially, my problem is that even though I have installed the  
ActiveRecord  
gem, I am unable to use it in a script.

Old development machine where everything works:  
Ruby 1.8.4  
Gems 0.8.11  
ActiveRecord gem installed 1.15.2

Results of IRB session on the old development machine

irb(main):001:0\> require ‘rubygems’  
=\> true  
irb(main):002:0\> require\_gem ‘activerecord’  
=\> true  
irb(main):003:0\> ActiveRecord  
=\> ActiveRecord

Ok, so that looks good. I can require the gem & then IRB knows what  
ActiveRecord is. Great.

New development machine where this doesn’t work  
Ruby 1.8.6  
Gems 0.9.4  
ActiveRecord gem installed 1.15.3

Results of IRB session on the new development machine

irb(main):001:0\> require ‘rubygems’  
=\> true  
irb(main):002:0\> gem ‘activerecord’  
=\> true  
irb(main):003:0\> ActiveRecord  
NameError: uninitialized constant ActiveRecord  
from (irb):3

So, something is up. In line 2 I’m using the command newer command ‘gem’  
instead of the depreciated ‘require\_gem’. But I get the same result even  
if  
I use the depreciated command.

Any ideas? Something I forgot to install on this new machine? Or some  
weird  
configuration change I made on the old machine that I didn’t copy over.

Thanks for any advice,

Ian

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [July 16, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/odd-requirement-behavior-between-two-environments/109557/2 "2007-07-16T21:12:58Z")

</div>

On 7/16/07, Ian W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):001:0\> require ‘rubygems’
> 
> Any ideas? Something I forgot to install on this new machine? Or some weird  
> configuration change I made on the old machine that I didn’t copy over.

require\_gem / gem are not the same as require. They’re meant for  
locking gems to specific versions or making sure they exist, not  
loading libraries, e.g.

gem “ruport”, “=1.0.1”

Also, with that in mind note that gem names don’t always coincide with  
library names, so you actually will need to do this:

require “rubygems”  
require “active\_record”

In earlier versions of RubyGems, it was possible for the require\_gem  
command to autoload libraries, this is no longer the case.

Hope that helps…

-greg

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [July 16, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/odd-requirement-behavior-between-two-environments/109557/3 "2007-07-16T21:16:59Z")

</div>

On 7/17/07, Ian W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> =\> true  
> irb(main):003:0\> ActiveRecord  
> NameError: uninitialized constant ActiveRecord  
> from (irb):3

“gem” doesn’t perform an implicit require; it simply modifies $: to  
include the path to the gem.

irb(main):001:0\> old = $:.dup  
=\> [“/usr/lib/ruby/site\_ruby/1.8”,  
“/usr/lib/ruby/site\_ruby/1.8/i686-linux”, “/usr/lib/ruby/site\_ruby”,  
“/usr/lib/ruby/1.8”, “/usr/lib/ruby/1.8/i686-linux”, “.”]  
irb(main):002:0\> require ‘rubygems’  
=\> true  
irb(main):003:0\> gem ‘activerecord’  
=\> true  
irb(main):004:0\> $: - old  
=\> [“/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/bin”,  
“/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib”,  
“/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/bin”,  
“/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib”]  
irb(main):005:0\> require ‘activerecord’  
LoadError: no such file to load – activerecord  
from  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
from (irb):5  
irb(main):006:0\> require ‘active\_record’ #sheesh  
=\> true  
irb(main):007:0\> ActiveRecord  
=\> ActiveRecord

martin

---

<div class="post-metadata">

**Author:** ![ian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/bb73d2/32.png) [@ian](https://www.ruby-forum.com/u/ian)\
**Post date:** [July 16, 2007, 9:26pm UTC](https://www.ruby-forum.com/t/odd-requirement-behavior-between-two-environments/109557/4 "2007-07-16T21:26:01Z")

</div>

On 7/16/07 2:05 PM, “Gregory B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Results of IRB session on the new development machine  
> > instead of the depreciated ‘require\_gem’. But I get the same result even if
> 
> -greg

Thank you, that seems to have moved me forward.

Ian
