views:

33

answers:

1

I want to configure gem to only use system gems - never those in $HOME/.gem. This is because I'm writing a script that will access Gem.path and I don't want it to return the path to gems in my home directory.

I'm pretty sure I haven't explicitly set GEM_HOME or anything like that in my .bashrc, .bash_login etc.

But Gem.path returns my homedir gems first:

irb
> Gem.path
=> ["/home/nfm/.gem/ruby/1.9.1", "/usr/local/lib/ruby/gems/1.9.1"]

Can I stop this from happening? Where is it configured? Or is it just the default to look in homedir first?

If I can't configure this, can I return the system path for gems with regexp hackery?

More details:

which ruby
/usr/local/bin/ruby
ruby --version
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]

gem env
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/1.9.1
     - /home/nfm/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/

Update:

So apparently this can be configured in ~/.gemrc:

# Note the use of a symbol before the colon - the string version doesn't work!
:gempath:
  - /usr/local/lib/ruby/gems/1.9.1

However, this does not seem to take effect if you fire up irb. This has something to do with the fact that the config file is YAML, and apparently yaml isn't loaded when irb starts (not sure on this one!):

$ irb
> Gem.path
=> ["/home/nfm/.gem/ruby/1.9.1", "/usr/local/lib/ruby/gems/1.9.1"]
> Gem.configuration.path
=> ["/usr/local/lib/ruby/gems/1.9.1"]
# Ready for a WTF moment?
> Gem.path
=> ["/usr/local/lib/ruby/gems/1.9.1"]

So, the answer below seems like the only consistent way to get the correct behavior, even though you'd assume that ~/.gemrc would work and would be a nicer way to wrap you config up.

However, setting :gempath: in my ~/.gemrc worked in the context of the script being in my Rakefile in a Rails app, presumably because yaml is explicitly loaded.

Not sure exactly what's going on with yaml, but this explanation seems consistent with what I'm seeing here.

Mod up! :P

+3  A: 

Hi,

overwrite it here:

#in ~/.bashrc
export GEM_PATH=/usr/local/lib/ruby/gems/1.9.1
sled
After mucking around for a while, this does seem to be the only way to get the correct behaviour. See updated question for an explanation of why config in `.gemrc` didn't work for me.
nfm