Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
When I run gem list --no-versions, I get an error message as shown in the link here. How do you backup if you are running windows? – Ishan Dec 16 '12 at 2:37
Try a normal gem list, then edit out the versions. You'll have to do everything manually (open the gem name file in notepad and use the up arrow and replace the names to make it easier). Also, if you are going to Windows again, please install Cygwin. You can get Ruby, Gems, and Rails by following this. Cygwin is a POSTIX-compliant interface to Windows, meaning its commands and shell are loads better than cmd.exe. – bb010g Dec 16 '12 at 3:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .