Reputation: 4269
I wrote a script todo.rb
, whose first line is #!/usr/bin/env ruby
. However, running this script gives the following error:
λ ~/ ruby todo/todo.rb
/Users/xjia/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- highline/import (LoadError)
from /Users/xjia/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from todo/todo.rb:6:in `<main>'
I have already installed the gem highline
:
λ ~/ which gem
/Users/xjia/.rvm/rubies/ruby-1.9.3-p0/bin/gem
λ ~/ gem install highline
Successfully installed highline-1.6.15
1 gem installed
Installing ri documentation for highline-1.6.15...
Installing RDoc documentation for highline-1.6.15...
λ ~/ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-darwin11.2.0]
- INSTALLATION DIRECTORY: /Users/xjia/.rvm/gems/ruby-1.9.3-p0
- RUBY EXECUTABLE: /Users/xjia/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/xjia/.rvm/gems/ruby-1.9.3-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/xjia/.rvm/gems/ruby-1.9.3-p0
- /Users/xjia/.rvm/gems/ruby-1.9.3-p0@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
and I can require
it in irb
:
λ ~/ which irb
/Users/xjia/.rvm/rubies/ruby-1.9.3-p0/bin/irb
λ ~/ irb
irb(main):001:0> require 'highline/import'
=> true
However, require
in ruby
fails exactly the same:
λ ~/ which ruby
ruby: aliased to bundled_ruby
λ ~/ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
λ ~/ ruby -e "require 'highline/import'"
/Users/xjia/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- highline/import (LoadError)
from /Users/xjia/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from -e:1:in `<main>'
I'm using rvm under both Ubuntu and Mac OS X. From my Ubuntu box, this shebang line works fine. However, it sucks under OS X. So what's the reliable way to find out the usable ruby
?
Upvotes: 0
Views: 1828
Reputation: 53178
The problem is here:
λ ~/ which ruby
ruby: aliased to bundled_ruby
you need to check:
which bundled_ruby
and make sure it also has proper shebang:
#!/usr/bin/env ruby
finally removing the alias for ruby should solve the problem, you might want check my gem rubygems-bundler
which is by default installed with RVM - it provides more "intelligent" means of detecting and using bundler.
Upvotes: 1