chruby, and Ruby gems "cannot load such file — "

838 Views Asked by At

I recently moved to a new iMac and did a clean install. Consequently not everything works like it did on my MBP. I made several changes suggested by @awsmsce and have incorporated that into the following. Still have the problem.

A ruby script that uses the gem mini_exiftool throws an error when run from TextMate (same error when run from command line). Here's the beginning of the script.

#!/usr/bin/env ruby
require 'rubygems'
require 'fileutils'
include FileUtils
require 'find'
require 'yaml'
require "time"
require 'shellwords'
require 'mini_exiftool'

TextMate reports LoadError: cannot load such file — mini_exiftool and

method require in kernel_require.rb at line 55

Path to kernel_require.rb is /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb which possibly shows a problem. Not running the same ruby as where the gems are. But with changes recommended by @awsmsce now in /Users/gscar/.rubies/ruby-2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb so that's not the issue

Terminal chruby >> * ruby-2.5.1

ruby -v >> ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

gem list >> mini_exiftool (2.9.0)

exiftool -ver >> 11.17

TextMate PATH variable is $PATH:$HOME/.rubies/ruby-2.5.1/bin:$HOME/.rubies/ruby-2.5.1/shims:/usr/local/bin:/usr/texbin:/opt/local/bin

system('gem env'):

RubyGems Environment:
  - RUBYGEMS VERSION: 2.5.2.3
  - RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin17]
  - INSTALLATION DIRECTORY: /Users/gscar/.gem/ruby/2.5.1/gems
  - USER INSTALLATION DIRECTORY: /Users/gscar/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/gscar/.gem/ruby/2.5.1/gems/bin
  - SPEC CACHE DIRECTORY: /Users/gscar/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-17
  - GEM PATHS:
     - /Users/gscar/.gem/ruby/2.5.1/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Users/gscar/Library/Application Support/TextMate/Managed/Bundles/Bundle Support.tmbundle/Support/shared/bin
     - /Users/gscar/.rubies/ruby-2.5.1/bin
     - /Users/gscar/.rubies/ruby-2.5.1/shims
     - /usr/local/bin
     - /usr/texbin
     - /opt/local/bin

Gem.path: ["/Users/gscar/.gem/ruby/2.5.1/gems"]

I'm updating this after having been on a trip for a month and still need this script. I changed the order of the gems, shows that some download but not others. gem list shows mini_exiftool (2.9.0) among others. If I hard code to require '/Users/gscar/.gem/ruby/2.5.1/gems/mini_exiftool-2.9.0/lib/mini_exiftool.rb' then the script fails similarly on another gem.

2

There are 2 best solutions below

8
On

Okay, I think I have it now. Gonna take a swing:

set your PATH to the following:

export PATH=$PATH:$HOME/.rubies/ruby-2.5.1/bin:$HOME/.rubies/ruby-2.5.1/shims:/usr/local/bin:/usr/texbin:/opt/local/bin

set your TM_RUBY variable to:

$HOME/.rubies/ruby-2.5.1/bin/ruby

I think you currently have ruby added to the path, but not the binaries or shims.

If this isn't working, try puts Gem.path, and make sure it points to the right location.

Make sure the gem you are trying to call is where you expect it gem which mini_exiftool

If they are wrong, you might need to set these

export GEM_HOME=[WHATEVER YOUR GEM DIR IS] export GEM_PATH=[WHATEVER YOUR GEM DIR IS]

0
On

This now works. Unfortunately I'm not quite sure what the fix was and it may not be fair to call this an answer for that reason and that I still have problems running Ruby scripts from TextMate. I'm at

chruby ruby-2.6.2

TM_PATH is $HOME/.rubies/ruby-2.6.2/bin/ruby

PATH is $PATH:/usr/local/bin:/usr/texbin:/opt/local/bin

TM_RUBY is $HOME/.rubies/ruby-2.6.2/bin/ruby

Works with GEM_PATH and GEM_HOME not set. However when they are set I get this error:

/Library/Ruby/Site/2.3.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem rspec-core (>= 0.a) with executable rspec (Gem::GemNotFoundException)
from /Library/Ruby/Site/2.3.0/rubygems.rb:262:in `bin_path'
from /usr/local/bin/rspec:22:in `<main>'` 

which most likely has something to do with my PATH setting. I'm posting this now as I was back revisiting the issue. I can run the Ruby scripts from the command line which is a work around.