Matthias
Matthias

Reputation: 1953

Rails: Is it good practice to specify the versions for the gems in my app?

I'm new to rails and have a rather general question:

Is it good practice to specify the versions for the gems in my app? Or, should I leave out the version number and let it regularly fetch the latest updates

Upvotes: 0

Views: 213

Answers (1)

Albert Paul
Albert Paul

Reputation: 1208

The purpose of the Gemfile.lock file is to keep track of gem versions.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.

Upvotes: 1

Related Questions