Cannot load Shorturl gem (ruby ErrorLoad)

2019-06-01 23:24发布

问题:

I'm fairly new to Ruby and keep knocking my head against gems, but this latest puzzle has really got me stumped.

After using the gem install shorturl, I added the following headers to a file in my project:

require "rubygems"
require "shorturl"

class Controller < Autumn::Leaf

When I run the project I get the following error:

myfile.rb:3 in `require': no such file to load -- shorturl (LoadError)

I'm not sure what other information would be useful, except that without the require the script is working. I'm guessing I need to add the rubygems path to some variable, but I have no idea which. Any ideas?

回答1:

You can run gem environment to see the environment that RubyGems is running in. Under GEM PATHS should be listed the paths that RubyGems will search for gems.

Depending on if you installed the gem as root or not it will either be under somewhere like /usr/local/lib/ruby/gems/1.8 or somewhere within your home directory. You can use gem list -d shorturl to find out where it is installed. If where it is isn't listed in the GEM PATHS you will have to add it to the GEM_PATH environment variable. For example:

export "GEM_PATH=$GEM_PATH:/usr/local/lib/ruby/gems/1.8"

if that works you then need to add it to somewhere like your .bashrc to ensure its always loaded.



标签: ruby rubygems