Home > Uncategorized > Copy Ruby Gems Between Ruby Installations/Computers/Systems

Copy Ruby Gems Between Ruby Installations/Computers/Systems

July 26th, 2009

Surprising this isn’t better Google-documented.  Here’s how I do it.

Make a list of your existing gems in a text file (run from machine with gems already installed):

gem list | tail -n+4 | awk '{print $1}' > gemlist

Copy the file to your new system.  Make sure your new system has the packages installed that will be needed to build your gems (such as ruby1.8, ruby1.8-dev, rubygems1.8).  Then run:

cat gemlist | xargs sudo gem install

It’s run through each line of your gemlist file and run sudo gem install on it.  If you don’t sudo install your gems, you can remove that bit about sudo.

Or if you want to go for the gold with a single command line:

ssh -o 'StrictHostKeyChecking=no' #{gem_server} #{path_to_gem} list | tail -n+1 | awk '{print $1 $2}' | sed 's/(/ --version /' | sed 's/)//' | tail -n+3 | xargs -n 3 #{path_to_gem} install

After installing REE 1.8.7, I used a slight permutation of this to install my gems with Ruby 1.8.7 from their previous Ruby 1.8.6 installation (previous gem install was accessible as “gem”, REE 1.8.7 gem accessible as “/opt/ruby-enterprise-1.8.7-20090928/bin/gem”):

gem list | tail -n+1 | awk '{print $1 $2}' | sed 's/(/ --version /' | sed 's/)//' | tail -n+3 | xargs -n 3 /opt/ruby-enterprise-1.8.7-20090928/bin/gem install

That reinstalled all my existing gems with the REE 1.8.7 gem manager.

Bill Uncategorized

  1. September 14th, 2009 at 20:52 | #1

    Cool, I am going to try this for macports when I upgrade to snow leopard, too!

  2. December 12th, 2009 at 04:05 | #2

    Thanks for this, I just adapted the sed command to remove trailing comma: sed ’s/(/ –version /’ | sed ’s/,//’ | sed ’s/)//’

  1. No trackbacks yet.