0

我写了一个脚本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/

我可以requireirb

λ ~/ which irb
/Users/xjia/.rvm/rubies/ruby-1.9.3-p0/bin/irb
λ ~/ irb
irb(main):001:0> require 'highline/import'
=> true

但是,requireinruby失败完全相同:

λ ~/ 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什么?

4

1 回答 1

1

问题在这里:

λ ~/ which ruby ruby: aliased to bundled_ruby

你需要检查:

which bundled_ruby

并确保它也有适当的shebang:

#!/usr/bin/env ruby

最后删除 ruby​​ 的别名应该可以解决问题,您可能需要检查我的 gem rubygems-bundler,它默认与 RVM 一起安装 - 它提供了更“智能”的检测和使用捆绑器的方法。

于 2013-01-04T19:21:38.277 回答