简体   繁体   中英

ruby command line LoadError

When I try to include a library on the command line, I receive LoadError messages

$ ruby -v
ruby 1.8.7 (2012-06-29 patchlevel 370)

$ gem list | grep coderay_bash
coderay_bash (1.0.2)

$ ruby -rcoderay_bash /bin/coderay -v
ruby: no such file to load -- coderay_bash (LoadError)

$ ruby -rubygems -rcoderay_bash /bin/coderay -v
ruby: no such file to load -- coderay_bash (LoadError)

It looks to work with ruby 1.9.2

$ ruby -v
ruby 1.9.2p290 (2011-07-09)

$ ruby -rcoderay_bash /bin/coderay -v
CodeRay 1.0.7

In Ruby 1.8, anything you want to require that was installed with RubyGems cannot be accessed until you require 'rubygems' . 1.9 removes this requirement.

You have several options for this:

  • Just put require 'rubygems' at the top of your file. This is harmless for 1.9 and is probably the easiest thing, because it's in the code and no one using your app has to remember anything
  • Change your shebang line to #!/usr/bin/env ruby -rubygems This tells the Ruby interpreter to require rubygems, but allows users to avoid this by sending your file to ruby directly, if they are offended by RubyGems for some reason
  • Always run with ruby and use -rubygems , eg ruby -rubygems my_app.rb This has no dependencies on RubyGems in your code, and will work, but you have to remember to do it everytime, which is somewhat of a pain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM