Creating your own Gem Server, redux

One of the most popular landing pages for rambleon.org (which isn’t saying much) – is a post I put together in April, 2007 about running your own gem server.

Unfortunately it’s outdated. Set let me revisit it for those landing on the old page and looking to put together their own gem server. The nice thing is, gem has (almost) all the tools you need.

Setting up your server

  1. You need a web server. (yes I know you can run gem_server, but get a real one). You are on your own for that one. You also need a rubygems install on that box. You are also on your own for bootstrapping rubygems on that box and any other ones.
  2. Decide where you will put your gems (say in a “mycoolgems” directory off the docroot for your webserver)
  3. $ mkdir [docroot]/mycoolgems/gems
  4. Copy your .gem files that you want to host to $ [docroot]/mycoolgems/gems
  5. The gem suite of commands includes a generate_index command to generate a yaml-based index of your gems, and other supporting files. See gem help generate_index for more information

Pointing your systems to your own server

This used to be a complete PITA that involved rebuilding the sources gem. No more! After you install rubygems – just make sure to do a:

gem sources --remove http://gems.rubyforge.org

and a

gem sources --add http://yourwaycool.gem.source

That’s All Folks (probably)

Voila! You just managed to point your server to your own gem server! Install away.

It’s good to keep one box pointed to http://gems.rubyforge.org – and take advantage of the new “gem outdated” command to keep track of changes in your installed gems that have been deployed to rubyforge.

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 http://gems.rubyforge.org 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.