Search code examples
rubyrubygemssearch-path

Ruby/Linux Installed gems not loaded


I am setting up an new Ubuntu 18.04 VM and am having problems with my Ruby applications. Ruby is version 2.5.1 (standard with 18.04). Gems are installed with sudo as they are loaded by apps running under several different uids.

They don't find any of the installed gems!

rful011@secgenprd02:~$ sudo gem install sys-proctable
Fetching: sys-proctable-1.2.5.gem (100%)
Successfully installed sys-proctable-1.2.5
Parsing documentation for sys-proctable-1.2.5
Installing ri documentation for sys-proctable-1.2.5
Done installing documentation for sys-proctable after 0 seconds
1 gem installed

rful011@secgenprd02:~$ irb
irb(main):001:0> require "sys/proctable"
Traceback (most recent call last):
    4: from /usr/bin/irb:11:in `<main>'
    3: from (irb):1
    2: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
LoadError (cannot load such file -- sys/proctable)

gem env says:

  - GEM PATHS:
    - /var/lib/gems/2.5.0

ls:

rful011@secgenprd02:~$ ls -ld /var/lib/gems/2.5.0/gems/sys-proctable-1.2.5/
drwxr-xr-x 6 root root 181 Jul  7 17:26 /var/lib/gems/2.5.0/gems/sys-proctable-1.2.5/

Any suggestions on how to diagnose this issue welcome! I am at the point where I am considering wiping the VM and starting again -- unfortunately this is not trivial.

One additional datapoint. The gems were originally installed by puppet which runs with a umask that denies 'other' access (known feature of puppet package gem provider). I uninstalled them by hand and then reinstalled them from a process with the correct umask. I have carefully checked the permission of all the the files in the installed gems.

My best guess is that there is some thing else which has the wrong permission which is stopping the gems from being loaded.


Solution

  • I finally tracked this down, it was a file permission problem, due to the initial install happening with the incorrect umask.

    rful011@secgenprd02:~$ ls -ld /var/lib/gems/2.5.0/*
    drwx------  2 root root    6 Jun 26 11:18 /var/lib/gems/2.5.0/build_info
    drwx------  2 root root 4096 Jul  7 17:26 /var/lib/gems/2.5.0/cache
    drwx------  3 root root   33 Jul  5 10:04 /var/lib/gems/2.5.0/doc
    drwx------  3 root root   26 Jun 26 11:18 /var/lib/gems/2.5.0/extensions
    drwxr-xr-x 29 root root 4096 Jul 13 08:28 /var/lib/gems/2.5.0/gems
    drwx------  2 root root 4096 Jul 13 08:28 /var/lib/gems/2.5.0/specifications
    

    I had fixed the gems directory but not the others. In particular specifications is accessed when loading gems, fixing this alone got the gems loading.

    What is very confusing is that the file permission failure is caught by ruby and all you get is the erroneous/confusing "cannot load such file -- <gem name>"