---
title: "Gem List to Gemfile"
description: "Say you have n-machines that needs to be in sync with their ruby gem versions, we can have one system to update all as per."
url: "https://h3manth.com/scribe/gem-list-gemfile/"
canonical_url: "https://h3manth.com/scribe/gem-list-gemfile/"
markdown_url: "https://h3manth.com/scribe/blog/gem-list-gemfile.md"
publishDate: "2013-03-20T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["ruby","javascript"]
word_count: 182
reading_time_minutes: 1
x_markdown_tokens: 394
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Gem List to Gemfile

> Say you have n-machines that needs to be in sync with their ruby gem versions, we can have one system to update all as per.

Say you have n-machines that needs to be in sync with their ruby gem versions, we can have one system to update all as per need and then create this Gemfile and distribute the same.﻿

Here is a simple chunk of code that would help to convert all the gems install to a gemfile, which can later be used with bundler.

```ruby
def make_gemfile [:each_default,:each_normal].flat_map { |sym|
  Gem::Specification.to_enum(sym).map{|spec| 
    "gem \"#{spec.name}\", :version => \"#{spec.version}\""
  } 
}
end
```

On invocation, you will see something like :

```ruby
 gem "bigdecimal", :version => "1.2.0" gem "io-console", :version => "0.4.2" gem "json", :version => "1.7.7" gem "minitest", :version => "4.3.2" gem "psych", :version => "2.0.0" gem "rake", :version => "0.9.6" gem "rdoc", :version => "4.0.0" gem "test-unit", :version => "2.0.0.0" gem "gita", :version => "0.0.1" gem "howdoi", :version => "0.0.3" gem "minitest", :version => "4.6.2" gem "nokogiri", :version => "1.5.6" gem "rubygems-update", :version => "2.0.2" gem "test-unit", :version => "2.5.4" 
```

P.S : Thanks to @hanmac for providing a better ruby hack, compared to my python parsing :D

Note : ` [].flat_map(&blk) is same as [].map(&blk).flatten(1)`
