Why 'bundle install' is slow (and how to make it fast)
I use Bundler's command bundle install
with Capistrano and it used to takes many seconds to complete. The reason was that Bundler fetched all required gems unless they were already installed and then checked for all dependent gems if there is are newer versions available and installed these. It's the last step that took so long.
The solution is to do a bundle lock
in development and to add the resulting file Gemfile.lock
to your VCS. During bundle lock
, Bundler writes all dependent gems and their specific version numbers to Gemfile.lock
. This way, it will only search these gems and will not try to use the latest ones. And because these gems are already deployed after the first deployment, bundle install
can complete quickly.
Another advantage is that your deployment environment will use exactly the same gem versions as your development system.
The bundler home page explains how to use bundle lock.
Update: The latest bundler version 0.9.26 always performs a bundle lock
implicitly when you run bundle install
.
Update 2: This post is irrelevant for a while now.