3. Trouble Shooting Questions

After I updated RubyGems, I tried to install a gem and got parse errors:

[C:\]gem install rails
"c:\ruby\bin\ruby.exe" "c:\ruby\bin\gem" install rails
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
ERROR:  While executing gem ... (ArgumentError)
    parse error on line 2, col 92:
     `@gems{???"?rwdtinker-1.60o:?Gem::Specification:?@email"?steven@superant.com:?@requirements['

Any idea what’s going on? Can I roll back to the rubygems version I had before?

Answer

It sounds like your source cache is either corrupted or not in the format expected. Around version 0.8.5 or so we switched from a YAML based cache to a marshalled cache (with a significant increase in speed). If you run a 0.8.5 or later version of gems and then later try to go back to a pre-0.8.5 version, the earlier version is confused by the data in the cache (post 0.8.5 versions are smart enough to just toss the cache if it looks bad).

To fix, just delete the source cache file (the file named source_cache in the directory reported by the ‘gem env gempath’ command). If you are on a unix-like OS and the source_cache is in a protected directory, you might have another copy of the source cache available in a user owned directory (probably $HOME/.gem/source_cache). Delete that copy as well.

I have a problem with RubyGems. It doesn’t matter what I try to install with, it freezez.

Particulary I tried to execute:

gem install rails --include-dependencies

but the command freezez at the following message:

"Updating Gem source index for: http://gems.rubyforge.org"

Answer

[I lost my internet connection while composing the answer to this question. Unfortunately, I now no longer recall what I intended to write. The answer (or at least part of the answer) is buried deep in the RubyGems mail archive. I’ll try to update this after a bit of research. Sorry for leaving this question hanging.]

When I run the gem command, I get the following error message:

 ruby: No such file to load -- rubygems (LoadError)

What’s wrong?

Answer

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.

Require returns false when loading a file from a gem. Usually require will return true when it has loaded correctly. What’s wrong?

Answer

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.

As we said, it is not a problem, but it sure is confusing to folks doing requires in an irb session. Future versions of RubyGems will correct this behavior.