69

Could you tell me, whats the difference between:

$Bundle update

and

$Bundle install

2 Answers 2

95

bundle update and bundle install can both install the gems you specified in Gemfile but missing in gems.

But bundle update does one thing more to upgrade:

  1. If the gems specified in Gemfile don't have version, it will upgrade to whatever latest.
  2. If the gems specified in Gemfile have version controlled with ~>, it will upgrade to the latest at the final digit, the patch version.

    For example, if you have a gem in Gemfile

    'foo_gem', '~> 2.1.0'
    

    bundle update will check if newer version of 2.1.x is available in cloud. Say your current version is 2.1.2 and what's latest in cloud is 2.1.5, it will install 2.1.5. But if 2.2.6 is the newest, it won't do anything.

Better practice in my opinion

  1. Always add version to critical gems like rails.

  2. Stick to bundle install(or bundle which is default to install) in most cases. Only do bundle update when it's really necessary and you are fully prepared for the result.

8
  • So, as I good understood: if I have 'foo_gem', '~> 2.1.0' , the main difference is: bundle update - install version 2.1.* (latest), and bundle install - install version 2.1.0
    – matDobek
    Commented May 11, 2013 at 15:01
  • 4
    @shuffla90, in this case, bundle install will still install the latest gem say 2.1.5 if you don't have this gem. But, if you already have this gem at 2.1.1, bundle install will do nothing.
    – Billy Chan
    Commented May 11, 2013 at 19:31
  • got it, muchos gracias, for your time :)
    – matDobek
    Commented May 12, 2013 at 8:59
  • Just for more details have a look at ryanbigg.com/2011/01/why-you-should-run-bundle-update and robots.thoughtbot.com/rubys-pessimistic-operator
    – Amit Patel
    Commented Dec 11, 2014 at 5:43
  • 2
    @zack, the reason is the latest version might be better, but is not guaranteed to work nicely with your app. Some APIs might change, some might be deprecated, some results might be returned differently. You never know unless you studied the doc. It's always better to only upgrade when really needed, with intention.
    – Billy Chan
    Commented Feb 23, 2015 at 5:25
6

Bundle Updates the gems specified (all gems, if none are specified), ignoring the previously installed gems specified in the Gemfile.lock. In general, you should use bundle install to install the same exact gems and versions across machines.

1
  • And bundle install could recommend doing bundle update. e.g. bundle install could say, for a gem The bundle currently has blahgem locked at 5.11.1. Try running bundle update blahgem, (or just bundle update).
    – barlop
    Commented Jan 19, 2018 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.