Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Various ways to update Ruby gems

Tags:

ruby

rubygems

I'd like to understand the differences between the following Ruby/Bundler/RubyGems commands:

  1. bundle install
  2. bundle update
  3. gem install my_gem.gem
  4. gem update my_gem.gem

Assume my_gem is hosted on rubygems.org. I'm running Ruby 1.8.7, RubyGems 1.8.10 and Bundler 1.0.21. I also have rvm 1.8.6 available (but I'm not sure rvm is relevant when updating gems).

Also I'm using git for version control. Does it make sense for me to manually update the Gemfile? Or does this happen automatically when one of the above commands are run?

like image 979
SundayMonday Avatar asked Aug 04 '26 08:08

SundayMonday


1 Answers

The Gemfile is what you change to add/remove/update the gems (or just the versions of gems) running in your app. Gemfile.lock is the file that's automatically updated by bundler. In fact, you shouldn't try to manually update Gemfile.lock: first, because it's auto-generated, and second it's not intended to be altered by hand, and you're likely to confuse bundler if you alter it yourself.

To answer you list:

  1. bundle install installs any new/updated gems and dependencies - but if they are already installed, nothing is done
  2. bundle update runs through your installed gems, and grabs the newest, allowed versions, as defined in your Gemfile
  3. gem install my_gem.gem bypasses bundler, and installs the gem at the system level (i.e. outside your application's code bundle)
  4. gem update my_gem.gem bypasses bundler, and updates the gem at the system level (i.e. outside your application's code bundle)

So, one set of commands installs (if not already installed), one set of command updates to latest versions the gems that are already installed, one set of commands does these things within the scope of your app only (your application code bundle), and one set of commands does these things at the system level.

Git is not relevant to your question here.

like image 158
jefflunt Avatar answered Aug 07 '26 08:08

jefflunt