Borked gems and when cache is not cache
Friday, October 9th, 2009Somehow, someway my gem installation became subtly corrupt. Specifically, many of my gems are not available in the cache directory. That’s not a very intuitive erroneous situation, but there are gem commands that clearly expect a gem file in the cache directory -and they can’t recover the situation if the file is missing. Doesn’t sound like my definition of a cache, but it’s time to move on.
Symptom:
1. whiny errors while attempting to unpack a gem like:
[cch1@bimota:~/Documents/Development/t]$ gem unpack exifr
ERROR: While executing gem … (Gem::Exception)
Cannot load gem at [/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/cache/exifr-0.10.7.gem] in /Users/cch1/Documents/Development/t
or
[cch1@bimota:~/Documents/Development/t]$ gem pristine exifr
Restoring gem(s) to pristine condition…
ERROR: Cached gem for exifr-0.10.7 not found, use `gem install` to restore
2. Indeed, no .gem file exists in the referenced cache directory.
Note that in OSX Leopard, gems are typically installed in several locations:
[cch1@bimota:~/Documents/Development/t]$ gem env paths
/Users/cch1/.gem/ruby/1.8:/Library/Ruby/Gems/1.8:/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
My theory is that earlier versions of gem (such as the one I got with my distribution of Leopard in early 2008) had problems installing and updating gems other than those originally packaged with the system. Using the gems by requiring the library file typically worked fine. But by not building the cache file (or perhaps building it in the wrong one of the multiple gem directories), problems crept up months later trying to unpack the gem.
Sadly, the only solution I can find is to re-install the gem:
[cch1@bimota:~/Documents/Development/t]$ gem list exifr
*** LOCAL GEMS ***
exifr (0.10.7)
[cch1@bimota:~/Documents/Development/t]$ sudo gem install exifr –version ‘=0.10.7′
Password:
Successfully installed exifr-0.10.7
1 gem installed
Installing ri documentation for exifr-0.10.7…
Installing RDoc documentation for exifr-0.10.7…
Now the commands that depend on the “cached” version will work:
[cch1@bimota:~/Documents/Development/t]$ gem unpack exifr
Unpacked gem: ‘/Users/cch1/Documents/Development/t/exifr-0.10.7′