我写了一个脚本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
inruby
失败完全相同:
λ ~/ 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
什么?