Bundler maintains a consistent environment for ruby applications. It tracks an application’s code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run. This is the definition of bundler available on its site. The site already have all the detail in concise way. I’am just paraphrasing them here with my own observation.
First, thing is that it is really good gem to manage all your gem dependency as well as there consistency. So, better to install it at the start of your project. If You are using RVM it automatically install it for you under global gemset. The global gemset get created for every ruby version you installed. The default gems created within global gemset is as below.
$ gem list #listing all the gem within global gemset
*** LOCAL GEMS ***
Now, any gemset you create, inherit all the gem within global gemset, show basically you do not need to install them. So let say, our bundle is working.
So, what is the problem ..???
The problem is that, if you have multiple version of some executable(which is used to run other files) like rake, rspec, cap etc in your gemset , it will throw error due to conflict. The common one is for rake below :
$ rake db:migrate # any command with rake will fail with this error
You have already activated rake 10.0.3, but your Gemfile requires rake 10.0.2
When I checked my gemset, I do find multiple versions of rake as below
rake (10.0.3, 10.0.2, 0.9.2.2)
1 -> prefix bundle exec to run all your exicutable # It will run the version associated with your gem file, thus removing the conflict
$ bundle exec rake db:migrate # it will run rake-10.0.2 associated with your gemfile
2 -> remove the gem causing the conflict # if you do not want to prefix bundle exec with your executable command like rake respec etc, remove the conflicting gem
$ gem uninstall rake -v 10.0.3
It is good practice to run all the executable commands with bundle exec prefix, which will ensure that your command will always work. It is must when you are writing deployment script with capistrano mina etc, so that your deployment do not fail due to conflicting executable