1

I'm working on an Ansible script to install my standard working environment (Ruby on Rails).

Ansible runs under sudo, and the gems that have been installed are only accessable under sudo too. If I do gem env as a normal user I get this:

$ gem env
/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:10:in `require': no such file to load -- rubygems/defaults (LoadError)
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:10
    from /usr/local/bin/gem:8:in `require'
    from /usr/local/bin/gem:8

When I open the file in question I can see the following:

#/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb

# -*- ruby -*-
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

gem_disabled = !defined? Gem

require 'rubygems/defaults'
require 'rbconfig'
require 'thread' # HACK: remove me for 1.5 - this is here just for rails

Line 10 is the require 'rubygems/defaults' line.

Doing sudo gem env shows me the following:

$ sudo gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.4.2
  - RUBY VERSION: 1.8.6 (2010-09-02 patchlevel 420) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
  - 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.8
     - /home/max/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document --no-ri --no-rdoc"
  - REMOTE SOURCES:
     - http://rubygems.org/

Can anyone tell me what I need to do to make the gems accessable to my regular user in non-sudo mode?

EDIT: A bit more info. I had a look for where it should be loading rubygems/defaults from, by using locate:

$ locate rubygems | grep default
/usr/lib/ruby/1.9.1/rubygems/defaults.rb
/usr/local/lib/ruby/gems/1.8/gems/rubygems-update-1.2.0/lib/rubygems/defaults.rb
/usr/local/src/rubygems-1.4.2/lib/rubygems/defaults.rb

Guessing that it should be loading /usr/local/lib/ruby/gems/1.8/gems/rubygems-update-1.2.0/lib/rubygems/defaults.rb, I changed the require line to have the full path to this:

require '/usr/local/lib/ruby/gems/1.8/gems/rubygems-update-1.2.0/lib/rubygems/defaults'

and that seemed to work - it then failed on the require 'thread' line, which I could presumably do the same thing for.

So, it looks like Ruby needs to be told which folder to start in, when looking for things to include. Maybe this is what I need to do? I don't know the best way to do it though...

  • Did you ever solve this @max-williams? – Luceos Nov 23 '18 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.