Have you ever been without internet and needed a gem but it’s in the wrong RVM gemset? How about attempting to correct a problem with a production environment and need to clone the exact gems available? Perhaps you are attempting a full app stack backup for compliance purposes?
Gem::Repackager packages one or more of your installed gems back into .gem files for easy transportation. Gem::Repackager comes with a command-line utility to facilitate, with easy extensibility in the code as well.
It’s a gem, so install it.
gem install gem_repackager or add it to bundler.
The command-line utility is as follows:
gem_repackager DIRECTORY [options]
This will repackage all gems in
DIRECTORY and place the resulting .gem files in
DIRECTORY refers to the location of your installed directories. Note that this is the directory that contains
gems, etc, and not the
gems directory itself. In RVM, this is usually along the lines of
~/.rvm/gems/GEMSET or simply
gem_repackager places the packaged gems into
DIRECTORY. To change this, pass the
--destination DIR parameter and the resulting gems will be moved there.
--gems gem-version[,gem-version,...]- A comma-separated list of gems in “GEM-VERSION”
--destination DIR- Location to store the packaged .gem files to. If this is not passed, it will default to
--[no]-verbose- Toggle verbose mode. This includes Gem::Specification warnings, so this could get noisy.
Here’s an example of packaging all gems in my current RVM gemset to a custom directory:
gem_repackager $GEM_HOME --destination=~/gem_export
And here is how you would package all of the rspec 2.11.0 gems to the default directory:
gem_repackager $GEM_HOME --gems rspec-2.11.0,rspec-core-2.11.0,rspec-expectations-2.11.2,rspec-mocks-2.11-1
Pull requests welcome, preferably with tests because I am lazy and do not want to run every command to make sure changes did not break anything.
Written by Andrew ‘Cad’ Nordman thanks to not having any internet access for a week and needing to get things done.