130

How do I force Bundler to reinstall all of the gems in my gemfile? Or, how do I force Bundler to uninstall all of the gems it installed so I can then reinstall them myself?


I saw rails bundle clean, but this question explains how to remove gems that bundle installed but are no longer in the gemfile.

And How to reinstall a gem using bundler explains how to reinstall a single gem. I would like to reinstall all of my gems at once.

Kevin
  • 14,655
  • 24
  • 74
  • 124

5 Answers5

243
bundle install --redownload

See the reference for bundle install: https://bundler.io/v2.2/man/bundle-install.1.html

or

bundle install --force

For older versions of bundler

Thilo
  • 17,565
  • 5
  • 68
  • 84
Kevin
  • 14,655
  • 24
  • 74
  • 124
  • 11
    [DEPRECATED] The `--force` option has been renamed to `--redownload` – Rimian Feb 10 '20 at 23:47
  • 2
    @Rimian I don't think `--force` option is deprecated. [Bundler docs](https://bundler.io/v2.0/man/bundle-install.1.html) say that `--redownload` is an alias for that option, but nothing about deprecating `--force`. – Rouger Feb 11 '20 at 13:26
  • 4
    I copied that straight from std out. I guess we will find out at some point! – Rimian Feb 11 '20 at 22:47
  • 2
    `--force` option still works but it raises a deprecation warning if you use it (bundler 2.1.4). I guess it will be totally deprecated in the next major upgrade – Pere Joan Martorell Sep 10 '20 at 08:18
  • 1
    Note: If you're doing this locally to test that a live deployment will succeed, then add the `--deployment` switch to force the usage of the exact versions specified in your Gemfile (and ignore patch upgrades like ~> 0.3.2 which would normally upgrade to e.g. 0.3.6). See https://stackoverflow.com/a/66791138/1852005 – stwr667 Aug 31 '22 at 12:19
7

Brutish but clever:

  1. Comment out your entire Gemfile. (Don't delete it)
  2. bundle clean
  3. Restore your Gemfile.
  4. bundle install
David Hempy
  • 5,373
  • 2
  • 40
  • 68
2

You can also delete the vendor directory and do bundle install again.

2

If you completely want to reinstall everything from scratch you can just, locate your gem dir, for example if you use rvm it would be ~/.rvm/gems then locate your ruby version alongside with gemset for example ruby-2.7.0@some_particular_gemset (it will be a dir) and then just delete it.

rm -rf ruby-2.7.0@some_particular_gemset

bundle install
1

Another way to deal with gem problems can be to sudo gem clean instead of reinstalling everything

Jose Paez
  • 747
  • 1
  • 11
  • 18