# Undefined method \`gem' for main:Object after rake rails:freeze:gems

**URL:** <https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587>\
**Category:** Rails\
**Created:** [February 29, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587 "2008-02-29T16:51:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dale](https://www.ruby-forum.com/u/dale)\
**Post date:** [February 29, 2008, 4:51pm UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587/1 "2008-02-29T16:51:01Z")

</div>

Help! I’m kinda stuck…I’m pretty sure that I somehow need to  
‘freeze’ RubyGem itself (aka gem) although given the error below, I’m  
not sure. I can’t downgrade & freeze to the rails version on the host  
since my app depends on some Rails2x stuff.

If indeed I need to ‘freeze’ gem’, is there standard way to do this?  
or any idea as to what exactly I’d need to do (i.e. how do I get my  
app to “see” the correct ‘gem’ command).

The reason I ask is because I’m getting this error message spewing  
from my app on a shared host:  
myHostDir/httpdocs/newsite/app/vendor/rails/activerecord/lib/…/…/  
activesupport/lib/active\_support/vendor.rb:5:  
undefined method `gem' for main:Object (NoMethodError) from /httpdocs/newsite/app/vendor/rails/activerecord/lib/../../ activesupport/lib/active_support.rb:26:in`require’  
from /httpdocs/newsite/app/vendor/rails/activerecord/lib/…/…/  
activesupport/lib/active\_support.rb:26  
from /httpdocs/newsite/app/vendor/rails/activerecord/lib/  
active\_record.rb:31:in `require' from /httpdocs/newsite/app/vendor/rails/activerecord/lib/ active_record.rb:31 from ./../config/../vendor/rails/railties/lib/initializer.rb:156:in`require’  
from ./…/config/…/vendor/rails/railties/lib/initializer.rb:156:in  
`require_frameworks' from ./../config/../vendor/rails/railties/lib/initializer.rb:156:in`each’  
from ./…/config/…/vendor/rails/railties/lib/initializer.rb:156:in  
`require_frameworks' from ./../config/../vendor/rails/railties/lib/initializer.rb:88:in`process’  
from ./…/config/…/vendor/rails/railties/lib/initializer.rb:49:in  
`send' from ./../config/../vendor/rails/railties/lib/initializer.rb:49:in`run’  
from ./…/config/environment.rb:13  
from dispatch.cgi:3:in `require’  
from dispatch.cgi:3  
 [client] Premature end of script headers: /  
httpdocs/newsite/app/public/dispatch.cgi

Of course the app gives:  
Application error  
Rails application failed to start properly"

The app is running fine on my development box with InstantRails 2.x  
specifically:  
rails: 2.0.2  
gem: 1.0.1  
ruby: 1.8.6 patchlevel 111  
Unfortunately my host is running rails 1.1.2, and I don’t have shell  
access so this is all the info I’ve got there:  
rails: 1.1.2  
gem: ???  
ruby: 1.8.4

Or am I totally stuck & have to see if they’ll upgrade ruby on the  
host?  
Thanks,  
Dale

---

<div class="post-metadata">

**Author:** ![dale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dale](https://www.ruby-forum.com/u/dale)\
**Post date:** [February 29, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587/2 "2008-02-29T17:06:57Z")

</div>

I should mention that the development box is winXP with instantRails  
2.

---

<div class="post-metadata">

**Author:** ![dale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dale](https://www.ruby-forum.com/u/dale)\
**Post date:** [February 29, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587/3 "2008-02-29T17:18:48Z")

</div>

On 29 Feb 2008, at 15:50, Dale wrote:

> Help! I’m kinda stuck…I’m pretty sure that I somehow need to  
> ‘freeze’ RubyGem itself (aka gem) although given the error below, I’m  
> not sure. I can’t downgrade & freeze to the rails version on the host  
> since my app depends on some Rails2x stuff.
> 
> If indeed I need to ‘freeze’ gem’, is there standard way to do this?  
> or any idea as to what exactly I’d need to do (i.e. how do I get my  
> app to “see” the correct ‘gem’ command).

That could be the case: the require\_gem method was replaced by gem in  
newer versions of ruby gems. (ie the problem here isn’t the gem  
command itself but the gem library.  
You should be able to convince ruby to load the gem library from  
somewhere else (either via the -I option or via fiddling with $LOAD\_PATH

Fred

---

<div class="post-metadata">

**Author:** ![dale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dale](https://www.ruby-forum.com/u/dale)\
**Post date:** [March 1, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587/4 "2008-03-01T18:56:55Z")

</div>

I tried a bunch of things…none of which worked. Fortunately the  
hosting provider was willing to upgrade to the latest ruby & gems.  
Which works great now! The downside is I’ll never probably know quite  
how to ‘freeze’ the gem command into the application.

For the curious, here’s what I tried:  
ran the follwing in my app/vendor/gems directory:  
gem unpack rubygems-update  
Then re-transferred the entire app to the host, trying several things  
(none of these worked):

- modifying environment.rb to include (also tried without the /bin at  
the end)  
ENV[‘GEM\_PATH’] = File.dirname( **FILE** )+’…/vendor/gems/rubygems-  
update-1.0.1/bin’

- modifying the config.load\_path in the environment.rb trying each of  
the following with & without /bin)

# config.load\_paths += %W( #{RAILS\_ROOT}/vendor/gems/rubygems-

update-1.0.1/bin )

# config.load\_paths += "#{File.dirname( **FILE** )}/…/vendor/gems/

rubygems-update-1.0.1/bin"

- modifying the dispatch.cgi “shebang” to:  
#!/usr/bin/ruby -I …/vendor/gems/rubygems-update-1.0.1/bin

- I tried the gemsonrails gem, but couldn’t get it to work with my  
custom rake deploy (all deploy does is copy app files to a directory I  
use to then ftp to the host)

So in summary, what worked…upgrade ruby & the gems on the server.  
-Dale

---

<div class="post-metadata">

**Author:** ![dale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dale](https://www.ruby-forum.com/u/dale)\
**Post date:** [February 29, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587/5 "2008-02-29T17:37:12Z")

</div>

On Feb 29, 10:18 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> That could be the case: the require\_gem method was replaced by gem in  
> newer versions of ruby gems. (ie the problem here isn’t the gem  
> command itself but the gem library.  
> You should be able to convince ruby to load the gem library from  
> somewhere else (either via the -I option or via fiddling with $LOAD\_PATH
> 
> Fred

Fred, so if I understand this correctly I need to find my development  
box’s gem path and bulk upload that to the server in something like:  
myHostDir/gems

Then modify my dispatch.\* stuff to use “/usr/bin/ruby -I myHostDir/  
gems”

Have I got that right?

Thanks again,  
Dale

---

<div class="post-metadata">

**Author:** ![dale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecd19e/32.png) [@dale](https://www.ruby-forum.com/u/dale)\
**Post date:** [April 17, 2008, 6:07am UTC](https://www.ruby-forum.com/t/undefined-method-gem-for-main-object-after-rake-railsgems/130587/6 "2008-04-17T06:07:24Z")

</div>

In case anyone ends up back here…my server reverted to the old rails  
gems. So I had to solve this problem for ‘real’  
Here’s a link to how I did it:  
[http://www.godale.org/blog/2008/04/freezing-rubygems-on-shared-server.html](http://www.godale.org/blog/2008/04/freezing-rubygems-on-shared-server.html)

-Dale
