Ruby Enterprise Edition Gem Install Script

Skip the waffle - take me to the script

If you're anything like me, as soon as you heard that the 2nd part to Phusion's mod_rails release was Ruby Enterprise Edition you were probably getting a little excited. The prospect of a version of Ruby that is COW friendly and lowers the amount of memory required to host Rails applications is indeed very interesting.

Now that Phusion have released Ruby Enterprise Edition , I set about having a play to set it up.

The installation is incredibly simple, as it does everything for you - compiles itself, installs itself into a private location and all of those good things. Once it's set up, it is a completely isolated version of Ruby that will happily co-exist with your existing Ruby installation.

However, this has a catch. Gems are not shared between the multiple installations (nor should they be!) and this means that any gems that you are using under your normal Ruby install will need to be installed under REE. Otherwise, changing mod_rails to use REE will likely cause lots of applications to be broken without the correct Rails version for example.

I have a whole heap of gems installed on my server currently, spanning across at least 4 different versions of Rails. As such, there were a lot of gems to install under REE. So, I wrote a script to do it automatically.

The Install Script

It's not perfect. It knows nothing about gems, and so it may re-install a gem a couple of times before it finishes. This means it may take longer that if it were "gem aware". It does, however, do it all for you so as that you don't have to. What do you want for nothing?a rubber biscuit?


# The command to run for your vanila Ruby 'gem' command
# The command to run for REE's 'gem' command
NEW_GEM='/opt/ruby-enterprise-1.8.6-20080507/bin/ruby /opt/ruby-enterprise-1.8.6-20080507/bin/gem'

output=`#{OLD_GEM} list`
new_list=`#{NEW_GEM} list`
output.each do |line|
        # Skip lines that don't look like a gem version
        matches=line.match(/([A-Z].+) \(([0-9\., ]+)\)/i)
        if matches then
                versions.split(', ').each do |ver|
                        cmd="#{NEW_GEM} install #{gem_name} -v #{ver} --no-rdoc --no-ri --backtrace -y" 
                        # See if this gem is already installed
                        if new_list =~ /#{gem_name} \(.*#{ver}.*\)/i then
                                puts "#{gem_name} #{ver} is already installed. Skipping" 
                                puts cmd

NOTE: You may need to tweak the NEW_GEM and OLD_GEM constants at the top if you've installed either your vanilla Ruby or REE into different locations. Also check that your shebang line at the very top is right for your particular Ruby installation.