Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 5 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. i.imgur.com/SZnlb.png. 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.