Freedom_Ben
Freedom_Ben

Reputation: 11953

Bundler: Initialize with currently installed gems

How can I initialize/create/generate a Gemfile for Bundler using the Gems I currently have installed?

For example, if I have the rails gem and the colorize gem already installed, and I start a new rails app, how can I generate a Gemfile that already includes the rails and colorize gems, ideally with their current versions, so I don't have to type them out manually?

Upvotes: 0

Views: 137

Answers (1)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84453

Appending Installed Gems to Your Gemfile

You can dump all your currently-installed gems into a Gemfile-like format with a little Ruby text munging and shell redirection. For example:

ruby -ane 'puts "gem #{39.chr}#{$F.first}#{39.chr}"' < <(gem list) >> Gemfile

You could then manually edit the Gemfile and remove the gems you don't want, or organize them into Bundler groups as needed.

Removing gems you don't want in your bundle might take longer than just typing them into the Gemfile in the first place, but your mileage may vary. At least it's nice to know it can be done!

Upvotes: 1

Related Questions