Your own gem server and Ruby 1.8.5

A while back, I wrote about creating your own gem server — which basically consisted of custom building a sources gem. Mainly because gem sources –remove at the time wouldn’t let you remove rubyforge from the sources list.

Thankfully, gem sources –remove now works great. And with RubyGems 0.9.5 — they’ve included a new gem generate_index command that will generate the indexes for you. So now — if you want to create your own gem server, you can run the web server software of your choice and use the gem generate_indixe -d [docroot]/mycoolgems command to build the indexes.

(If you do update the rubygems-update gem on your “client” systems, make sure to do a gem sources –add http://yourgemserver and a gem sources –remove from your sources. Or continue building your own sources gem.)

Unfortunately, through no fault of the RubyGems devs, this might not work on a system running Ruby 1.8.5 — like, say, Red Hat Enterprise Linux, version 5. The fault lies in Ruby itself. gem generate_index builds its index in /tmp — and uses FileUtils to move it out of /tmp and into the place you specified as the target directory (or ‘.’). If your servers are like mine, /tmp and your web server directories are on different partitions, and unfortunately FileUtils in Ruby 1.8.5 has a bug moving directories across partitions.

The bug was fixed, I think with this revision in March 2007 — and it’s in Ruby 1.8.6 (at least as of p110/111) — but it’s not in Red Hat’s 1.8.5 packages — and I’m not sure it qualifies as a security bug, so I doubt it will get backported.

Anyway, I went the configure/make/make install route (package purists, feel free to cringe, but I don’t want to make RPM’s and this is core enough for me to stay on top of). Your mileage may vary.