bundle install and bundle update

JiaHung Lin
2 min readSep 6, 2017

bundle install is a command we use to install the dependencies specified in your Gemfile.

Gemfile

Simply put, Gemfile is a format for describing gem dependencies for Ruby programs. Or you can say it contains the gems you need in this project.

Gemfile.lock

Gemfile.lock is a file records exact versions of all the gems you used the last time you know for sure that the application worked.

If there is error during the first time you install the gem, no Gemfile.lock file will be created. After you create your Gemfile.lock, every time you update, add or remove some gems install that, the Gemfile.lock will modify the version of the gem.

Again, if there is any error occurs while installing, the Gemfile.lock will not be updated and remained as the last state.

The reasonGemfile.lock is important is when other developers fork your project, the Gemfile.lock can make sure after they run bundle install, the app can run on their computers. Instead of installing the latest version of each gem then breaks the app.

bundle install

When we run bundle install in a project , if there is no Gemfile.lock exist, Bundler will fetch all remote sources, resolve dependencies and install all needed gems.

The way Bundler resolve the dependencies is, Bundler will check the dependencies of each gem, and find out the suitable version of gem for not creating any conflict.

If Gemfile.lock exists, which means all the versions and dependencies of each gem is recorded. When we update a version of a gem then run bundle install, only the gem will be updated. But if the dependency of new version of the gem is conflicted with any other gem, the current gem won’t be updated.

Since we didn’t successfully update the gem, so the Gemfile.lock file will remain as the last time it was successfully updated.

bundle update

What bundle update do is Bundler will fetch all remote sources, resolve dependencies and install all needed gems, even though there is a Gemfile.lock file.

You can image bundle update is the same as we remove the Gemfile.lock file and run bundle install.

Resource:

bundle install

bundle update

What is Gemfile

Gemfile

--

--