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?


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.

  • 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
  • I'd do a gem list --no-versions | sed '/^*/ d' for a clean output of installed gems. – sepehr Dec 17 '16 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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