Bundler is launched from your app's root directory so it makes sure all needed gems are present to get your app working.If for some reason you no longer need a gem you'll have to run the
gem uninstall gem_name
as you stated above.So every time you run bundler it'll recheck dependencies
EDIT - 24.12.2014
I see that people keep coming to this question I decided to add a little something. The answer I gave was for the case when you maintain your gems global. Consider using a gem manager such as rbenv or rvm to keep sets of gems scoped to specific projects.
This means that no gems will be installed at a global level and therefore when you remove one from your project's Gemfile and rerun bundle then it, obviously, won't be loaded in your project. Then, you can run bundle clean (with the project dir) and it will remove from the system all those gems that were once installed from your Gemfile (in the same dir) but at this given time are no longer listed there.... long story short - it removes unused gems.
Answer from Daniel on Stack OverflowBundler is launched from your app's root directory so it makes sure all needed gems are present to get your app working.If for some reason you no longer need a gem you'll have to run the
gem uninstall gem_name
as you stated above.So every time you run bundler it'll recheck dependencies
EDIT - 24.12.2014
I see that people keep coming to this question I decided to add a little something. The answer I gave was for the case when you maintain your gems global. Consider using a gem manager such as rbenv or rvm to keep sets of gems scoped to specific projects.
This means that no gems will be installed at a global level and therefore when you remove one from your project's Gemfile and rerun bundle then it, obviously, won't be loaded in your project. Then, you can run bundle clean (with the project dir) and it will remove from the system all those gems that were once installed from your Gemfile (in the same dir) but at this given time are no longer listed there.... long story short - it removes unused gems.
This will uninstall a gem installed by bundler:
bundle exec gem uninstall GEM_NAME
Note that this throws
ERROR: While executing gem ... (NoMethodError) undefined method `delete' for #<Bundler::SpecSet:0x00000101142268>
but the gem is actually removed. Next time you run bundle install the gem will be reinstalled.
After bundle update, how do you guys delete old version gems?
bundle clean --force removes gems bundled with Ruby
ruby on rails - How to uninstall all gems installed using `bundle install` - Stack Overflow
ruby on rails - What to do after removing a gem from the Gemfile? - Stack Overflow
When it's production, how do you guys delete old version's gem?
I see there are 2 way.
`bundle clean --force` vs `sudo gem clean`
which one is better? and what do you guys use?
Since we're using ruby you could do something like this I guess:
bundle list | ruby -e 'ARGF.readlines[1..-1].each {|l| g = l.split(" "); puts "Removing #{g[1]}"; `gem uninstall --force #{g[1]} -v #{g[2].gsub(/\(|\)/, "")}`; }'
NOTE: Only lightly tested.
Comment out all gems in your Gemfile and run
bundle clean --force
You can run just bundle or bundle install to install gems based on your Gemfile. That will remove the instance of mygem from your Gemfile.lock file. It will not, however, remove the gem from your system. To do that, run gem uninstall mygem.
Not completely related, but still helpful:
bundle outdatedwill show you the gems that aren't on the latest version. Don't get too tied up with this list - it's fairly common to have gems that aren't on the latest version, because some gems are installed as dependencies & one gem might be requiring an older version of another gem.bundle upgrade mygemwill upgrade just that gem, and will bring its dependencies up to date. That means that other gems might be upgraded or installed as well.- You can search RubyGems to see a gem's dependencies across each of its versions. As a gem user, you'll only need to be concerned with the 'Runtime Dependencies' list at the bottom of the gem's page.
Cleans up unused gems in your bundler directory: bundle clean --force