# Disobedient 'gem env' Causing Rails "undefined method \`gem'

**URL:** <https://www.ruby-forum.com/t/disobedient-gem-env-causing-rails-undefined-method-gem/103828>\
**Category:** Rails\
**Created:** [May 10, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/disobedient-gem-env-causing-rails-undefined-method-gem/103828 "2007-05-10T20:08:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![transonik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@transonik](https://www.ruby-forum.com/u/transonik)\
**Post date:** [May 10, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/disobedient-gem-env-causing-rails-undefined-method-gem/103828/1 "2007-05-10T20:08:12Z")

</div>

I’m setting up on a textdrive shared host, and have installed my gems  
to a local directory called ‘gems’. I did this by installing the gems  
on my ubuntu 7.04 system and tar’ing up the ‘gems’ to a like-named  
directory on the ‘gilford’ (FreeBSD 5.3) shared host. (a trick  
required because ‘gem update’ or ‘gem install’ busts txd’s memory  
limit during a zlib inflate of the gem repository hash - that is,  
memory allocation fails for even the smallest of gems)

After setting my GEM\_PATH and GEM\_HOME so that ‘gem query’ reports  
_only_ my locally installed gems (as expected), and this test:

[xxx@gilford ~]$ gem list rubygems  
\*\*\* LOCAL GEMS \*\*\*  
rubygems-update (0.9.2)  
RubyGems Update GEM

reports exactly what I expect, I next try ‘gem env’, which nonetheless  
reports a back-rev gem version( ! ):

[xxx@gilford ~/local]$ gem env  
Rubygems Environment:

- VERSION: 0.8.11 (0.8.11)
- INSTALLATION DIRECTORY: /users/home/xxx/gems
- GEM PATH:
  - /users/home/xxx/gems
  - /users/home/xxx/local/lib/ruby/site\_ruby/1.8

- REMOTE SOURCES:
  - [http://gems.rubyforge.org](http://gems.rubyforge.org)

(note that I have removed the ‘gilford’ system’s gem path altogether,  
in desperation. I’m trying to avoid all of txd’s gems, so that I am  
certain that only my local stuff is included)

So I download the rubygems-0.9.2.tgz and stick it in a ‘local’  
directory, and adjust the two GEM paths above, plus my normal shell  
PATH and LD\_LIBRARY\_PATH to use the ‘local’ bins and libs first. But I  
still get ‘gem env’ → 0.8.11

The actual ‘gem’ file in the ‘local/bin’ directory is simply some Ruby  
that does:

require ‘rubygems’  
Gem.manage\_gems

with a few more lines. Surely these lines are run with either  
GEM\_PATH or the .gemrc path? And I think both of these are right:  
‘gem query’ proves ‘GEM\_PATH’ is working, and the next paragraph  
shows .gemrc works as well.

(I also have a consistent .gemrc in my home dir. According to Jim  
Weirich’s note from Apr 3 2006, I think I’m doing the right thing:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/187403](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/187403)

In short: “All gems use GEM\_PATH, except for ‘gem’, which  
uses .gemrc.” This behavior is supported by a test in which I add or  
subtract ‘gilford’s’ gem path from my .gemrc: and as expected, my  
‘gem env’ output shows only the lines specified in .gemrc.

The reason I care so much about what ‘gem env’ says is because when I  
type “rails -v” I get:  
/users/home/xxx/gems/bin/rails:15: undefined method `gem’ for  
main:Object (NoMethodError)

which various posts say results from running current ‘rails’ with a  
back-rev ‘gem’.  
The shared host ‘gilford’ is running Ruby 1.8.4

---

<div class="post-metadata">

**Author:** ![transonik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@transonik](https://www.ruby-forum.com/u/transonik)\
**Post date:** [May 10, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/disobedient-gem-env-causing-rails-undefined-method-gem/103828/2 "2007-05-10T22:10:28Z")

</div>

‘gemwhich rubygems’ returns -\> /usr/local/lib/ruby/site\_ruby/1.8/  
rubygems.rb BAD!

But my .gemrc explicitly specifies a gempath of /home/users/xxx/local/  
lib/ruby/site\_ruby/1.8 , and this directory does in fact have a  
different version of ‘rubygems.rb’.

So why does ‘gemwhich rubygems’ find a file that is not on any path I  
know of?  
(‘require rubygems’ is supposed to employ the same lookup algorithm as  
‘gemwhich’)

Can anyone explain what it is doing?

---

<div class="post-metadata">

**Author:** ![transonik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/22d042/32.png) [@transonik](https://www.ruby-forum.com/u/transonik)\
**Post date:** [May 11, 2007, 12:24am UTC](https://www.ruby-forum.com/t/disobedient-gem-env-causing-rails-undefined-method-gem/103828/3 "2007-05-11T00:24:42Z")

</div>

‘rubygems’ itself is found via a Ruby $LOAD\_PATH lookup.

As the PickAxe book explains, this can be set by a ‘ruby -I xxx’  
invocation.  
But in the case of ‘gem’ itself, or of ‘rails’, there is no command  
line ‘-I’ option.

So the library lookup path is specified by $RUBYLIB.  
This is the Ruby analog to C’s $LD\_LIBRARY\_PATH

My .bash\_profile now contains:

export RUBYLIB=$HOME/gems/local/lib/site\_ruby/1.8  
export GEM\_PATH=$HOME/gems  
export GEM\_HOME=$HOME/gems

If I want some of txd’s stock (old) gems, I’d add their path as  
well.kk  
See [http://rubygems.org/read/chapter/15](http://rubygems.org/read/chapter/15)
