views:

356

answers:

1

It seems that on development machines (like on the Macbook), if we use bundle install --deployment, all the gems will be installed into the vendor/bundle folder and it just use more disk space if we have multiple Rails 3 projects (some project just for testing Rails 3). If it is not --deployment, then the gems will be in the "generic" folder instead of inside the project folder, and so can be shared across projects. Is this true?

Another thing is, do we need to add all files under vendor/bundle to our repository and push it? It seems that if we do it, we just jam up the repo, because if we don't, all the appropriate gems will be installed by bundle install using all the gems specified in Gemfile.lock anyway. (The Gemfile.lock is a small file in the repo). Is this true too?

+2  A: 

Yes! True.

When you use the --deployment flag, Bundler makes sure that every gem you need is vendored i.e. they are copied to a predetermined place your application's folder structure (which happens to be vendor/bundle in Rails by convention) This is good for two things.

First if you have limited permissions that prevent you from installing gems in your deployment machine, then let you have all the gems needed within your app.

Second, if you want to hack away at the actual code in the gems, you can do so on your vendored copies without affecting the system gems. The changes you make will only affect the application you're working on.

This vendoring approach used to have another use, that is making sure that you are using the specific version of a gem, and your application would keep working even if the system gems were upgraded to a higher version that would break your app. However, Bundler itself made this use case mostly obsolete, as it automated the installation and referencing of specific versions of gems.

And yes, vendoring would bloat your app's code. Gemfile.lock is just a list of the required gems. If you vendor your gems, they get copied into your app with all their might.

So, I recommend you don't vendor your gems (that also means don't use the --deployment flag) unless you have one of the reasons above.

edgerunner
then should the folder `vendor/bundle` be added to the repo? There is saying that if the files there contain binary files, then it will break the system if Peter uses Mac and Tom uses Linux, (or if the deployment machine is Linux). Should we use `bundle package` and then `bundle install --local` and should we add them to repo?
動靜能量
Normally no. Do not vendor your gems (unless you want to change them or your deployment machine doesn't let you to run `bundle install` in it) let alone add to the repo. It's a waste of space, and causes trouble if everybody uses different systems as you said.
edgerunner