How to backup ruby gems?

How do you backup ruby gems? I am re-installing the Operating System so I would like to know how to back up ruby gems so that I can re-install it when I have installed the Operating System?

Is it also possible to install gems on a computer without internet access?


Solution 1:

To get a list of the names of your gems, do gem list --no-versions. Make a directory (such as gem-exports) Save that list to a file inside that directory, then remove the headers and empty lines. (The automation options are for *nix systems.)

Take that list and

xargs gem unpack < $LISTNAME

inside the directory. This should take the gem names and run a gem unpack $GEMNAME on all of them. You will now have all of the gems' sources in their respective directories. Copy the directory to the new OS.

You can then, in the directory, run

xargs -I gemname gem build gemname/gemname.gemspec < $LISTNAME

This should build all the gems you just exported, without needing an internet connection. IF you have a connection, then you can just

xargs gem install < $LISTNAME

That will install the latest versions of all of them.