3. Trouble Shooting Questions
Not every library has a strict mapping between the name of the gem and the name of the file you need to require. First you should check to see if the files match correctly:
$ gem list RedCloth *** LOCAL GEMS *** RedCloth (4.1.1) $ ruby -rubygems -e 'require "RedCloth"' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- RedCloth (LoadError) from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' from -e:1 $ gem contents --no-prefix RedCloth | grep lib lib/case_sensitive_require/RedCloth.rb lib/redcloth/erb_extension.rb lib/redcloth/formatters/base.rb lib/redcloth/formatters/html.rb lib/redcloth/formatters/latex.rb lib/redcloth/formatters/latex_entities.yml lib/redcloth/textile_doc.rb lib/redcloth/version.rb lib/redcloth.rb $ ruby -rubygems -e 'require "redcloth"' $ # success!
If you’re requiring the correct file, maybe `gem` is using a different ruby than `ruby`:
$ which ruby /usr/local/bin/ruby $ gem env | grep 'RUBY EXECUTABLE' - RUBY EXECUTABLE: /usr/local/bin/ruby1.9
In this instance we’ve got two ruby installations so that `gem` uses a different version than `ruby`. You can probably fix this by adjusting a symlink:
$ ls -l /usr/local/bin/ruby* lrwxr-xr-x 1 root wheel 76 Jan 20 2010 /usr/local/bin/ruby@ -> /usr/local/bin/ruby1.8 -rwxr-xr-x 1 root wheel 1213160 Jul 15 16:36 /usr/local/bin/ruby1.8* -rwxr-xr-x 1 root wheel 2698624 Jul 6 19:30 /usr/local/bin/ruby1.9* $ ls -l /usr/local/bin/gem* lrwxr-xr-x 1 root wheel 76 Jan 20 2010 /usr/local/bin/gem@ -> /usr/local/bin/gem1.9 -rwxr-xr-x 1 root wheel 550 Jul 15 16:36 /usr/local/bin/gem1.8* -rwxr-xr-x 1 root wheel 550 Jul 6 19:30 /usr/local/bin/gem1.9*
You may also need to give `irb` the same treatment.
Require returns false when loading a file from a gem. Usually require will return true when it has loaded correctly. What’s wrong?
Nothing. Well, something. But nothing you need to worry about.
A false return from the require method does not indicate an error. It just means that the file has already been loaded.
RubyGems has a feature that allows a file to be automatically loaded when a gem is activated (i.e. selected). When you require a file that is in an inactive gem, the RubyGems software will activate that gem for you. During that activation, any autoloaded files will be loaded for you.
So, by the time your require statement actually does the work of loading the file, it has already been autoloaded via the gem activation, and therefore it returns false.
When I run the gem command, I get the following error message:
ruby: No such file to load -- rubygems (LoadError)
It looks like executing copy of Ruby does not have the RubyGems library installed. RubyGems was probably installed at one time (because the gem command is recognized), but it may have been installed on a different installation of Ruby than the one you are currently running.
Things to check
- Check that the installation of Ruby that is running is the same one that has RubyGems installed. On a unix system, the which command (or type command) will help figure this out.
- Verify that the currently running installation of Ruby does indeed have the RubyGems library installed. You should find a “rubygems.rb” file in the site_ruby/1.8 directory of the Ruby installation.
These mixup can easily happen after installing a new instance of Ruby, but the old instance preceeds the new one in the PATH list.
I have a problem with RubyGems. It doesn’t matter what I try to install with, it freezes.
Particulary I tried to execute:gem install rails —include-dependencies
but the command freezes at the following message:“Updating Gem source index for: http://gems.rubyforge.org”
You’ll need to upgrade RubyGems to a modern version. You can find instructions in the Downloads link at the top of this page.