开发者

Using installed gems in Ruby with 'require'

I do something like sudo gem install json. Then I do irb. Then I do require 'json'. Then it says no su开发者_如何学Goch file to load -- json


You need to make sure that RubyGems itself is loaded, for requiring gems to work.

There are several ways to do this. You could require 'rubygems' explicitly in each file you want to use the gems in, but that might get to be a pain. Or you could pass -rubygems into ruby when you execute it, but again, you'd need to remember to do that each time.

The best way would probably be to set the RUBYOPT environment variable to rubygems. For instance, you may add the following line to your .profile:

export RUBYOPT=rubygems


Try adding this first:

require 'rubygems'

RubyGems is a dependency manager as well as an installer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜