Skip to content

Instantly share code, notes, and snippets.

@semanticart
Created February 3, 2009 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semanticart/57746 to your computer and use it in GitHub Desktop.
Save semanticart/57746 to your computer and use it in GitHub Desktop.
# generate the commands to install all currently missing versions from the output of `gem list` from
# another box to your local machine. `gem list` should be of format
# actionmailer (2.2.2, 2.1.0)
# actionpack (2.2.2, 2.1.0)
# ...
# will_paginate (2.2.2)
# ZenTest (3.9.2)
#
# usage: ruby install_gems.rb /path/to/your/gem/list/output.txt
require 'rubygems'
require 'rubygems/command'
require 'rubygems/commands/query_command'
class Gem::Commands::QueryCommand
public :installed?
end
file = ARGV[0]
raise "Could not read from #{file}" unless File.exist?(file)
File.readlines(file).each do |line|
name, versions = line.strip.split(/ /, 2)
versions.gsub(/[\(\)]/, '').split(', ').map do |version|
unless Gem::Commands::QueryCommand.new.installed?(name, version)
puts "sudo gem install #{name} -v #{version}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment