Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby require problem (something to do with $LOAD_PATH)

I'm trying to use a gem i just installed (via sudo gem install excelsior) like so

require 'rubygems'

require 'excelsior'

...

This works fine in irb, but when I stick exactly the same code into an .rb file and try run it with ruby I get <internal:lib/rubygems/custom_require>:29:in require': no such file to load -- excelsior (LoadError)

I guess it has something to do with the load paths apparently being completely different in irb from ruby (I'm on a mac and don't remember exactly how I installed the version of ruby I'm using).

So how do I configure ruby to have the same loadpath as irb?

One extra piece of info: some gems work, but not all :S

like image 717
Nat Avatar asked Oct 19 '25 04:10

Nat


2 Answers

You can easily check what is in your irb load path:

irb(main):001:0> $LOAD_PATH

Then you can identify missing directories and include them in ruby by calling it with -I option (which may be used more than once):

ruby -I missing_dir_1 -I missing_dir_2 your_script.rb

Edit: There is a possibility, though I haven't tested it yet, that by installing Excelsior gem with sudo you've put it in a directory not accessible to ruby ran without sudo. Try sudo ruby your_script.rb.

like image 75
maro Avatar answered Oct 21 '25 17:10

maro


To see if the two executables are different versions of ruby (as suspected by some), ask it to do

puts RUBY_VERSION
like image 38
Andrew Grimm Avatar answered Oct 21 '25 17:10

Andrew Grimm