Should I specify exact versions in my Gemfile?

后端 未结 3 924
萌比男神i
萌比男神i 2021-01-30 02:50

I\'ve noticed that on rubygems.org a lot of the gems suggest you specify them by major version rather than exact version. For example...

The haml-rails gem...

         


        
3条回答
  •  梦毁少年i
    2021-01-30 03:31

    This is the purpose of the Gemfile.lock file - running bundle install with a Gemfile.lock present only installs using the dependencies listed in there; it doesn't re-resolve the Gemfile. To update dependencies / update gem versions, you then have to explicitly do a bundle update, which will update your Gemfile.lock file.

    If there wasn't a Gemfile.lock, deploying code to production would be a major issue because, as you mention, the dependencies and gem versions could change.

    In short, you should be generally safe using the pessimistic version constraint operator (~>) as rubygems.org advises. Just be sure to re-run your tests after you do a bundle update to make sure nothing breaks.

    There's a nice article by Yehuda Katz that has a little more info on Gemfile.lock.

提交回复
热议问题