我写了一个脚本todo.rb
,第一行是#!/usr/bin/env ruby
。但是,运行此脚本会出现以下错误:
λ ~/ 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>'
我已经安装了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/
我可以在require
中irb
:
λ ~/ which irb
/Users/xjia/.rvm/rubies/ruby-1.9.3-p0/bin/irb
λ ~/ irb
irb(main):001:0> require 'highline/import'
=> true
但是,require
中的ruby
失败完全相同:
λ ~/ 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>'
我在Ubuntu和Mac OS X下都使用rvm。在我的Ubuntu框中,这个shebang线工作正常。但是,它在OS X下很糟糕。那么找出可用ruby
的可靠方法是什么?
答案 0 :(得分:1)
问题在于:
λ ~/ which ruby
ruby: aliased to bundled_ruby
你需要检查:
which bundled_ruby
并确保它也有适当的shebang:
#!/usr/bin/env ruby
最后删除ruby的别名应该可以解决问题,你可能需要检查我的gem rubygems-bundler
,它默认安装了RVM - 它提供了更“智能”的检测和使用捆绑器的方法。