0

I get this error on the server that I'm trying to run a ruby script.

require: no such file to load -- ssch_mail_lib (LoadError)

However, on my workstation computer the script runs fine.

Here's relevant code.

#!/usr/bin/ruby
$: << './lib'
require 'ssch_mail_lib'

Output of $LOAD_PATH

/Library/Ruby/Site/1.8
/Library/Ruby/Site/1.8/powerpc-darwin11.0
/Library/Ruby/Site/1.8/universal-darwin11.0
/Library/Ruby/Site
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby/1.8/universal-darwin11.0
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/vendor_ruby
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin11.0
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin11.0
.
./lib

I've tripled checked the names and directories. They match.

Any ideas what I'm missing? Or why it would work fine on one machine but not on another? Thanks!

EDIT: They are both using Ruby 1.8.7.

EDIT2: The script only works when run via TextMate. It does not work, (LoadError), when using terminal.

David Nix
  • 3,324
  • 3
  • 32
  • 51
  • What version of Mac OSX and Ruby? What arch? – Linuxios Jun 05 '12 at 17:21
  • Intel. OS X Lion. The server is 10.7.3. My workstation is 10.7.4. Same version of Ruby on both, 1.8.7. – David Nix Jun 05 '12 at 19:47
  • If there is no other difference between the two, it would either be the difference in minor version number (very unlikely) or something with the environment vars and other things (also unlikely). I'm afraid I can't help you. This sounds stupid, but maybe you can add an `.rb` extension? – Linuxios Jun 05 '12 at 20:55
  • I thank you for trying to help me. See my most recent edit. Wonder what TextMate is doing that Terminal is not... – David Nix Jun 05 '12 at 21:49
  • 1
    One thing to be aware of: `.` refers to the current working directory of the process, which is not necessarily the same as the directory containing the file. If whatever is launching ruby on the server is doing so from a different directory, `./lib` will refer to a different directory than the one containing `ssch_mail_lib.rb` (which I’m assuming is directly under the main script file). – matt Jun 05 '12 at 23:18
  • @galacticfury: Then TextMate is setting an environment for your script. What environment does it set? – Linuxios Jun 05 '12 at 23:53
  • I think @matt is right. Looks like I should do something like this answer: http://stackoverflow.com/a/5998961/455265. The easiest being using Ruby 1.9's require_relative. – David Nix Jun 07 '12 at 14:55

1 Answers1

1

There is one fundamental difference between 1.8 and 1.9: require semantics. In 1.8, require handles relative and absolute paths. In 1.9, require can only be used for the standard library, not user defined files in relative paths or locations. For that, you have to use the Ruby 1.9 method require_relative. I'm guessing that one of your computers has 1.8, and the other 1.9. You can use a clause with RUBY_VERSION to make version specific code.

Linuxios
  • 34,849
  • 13
  • 91
  • 116