34

In Rails Gemfile, what are the differences between these :

gem "gemname", "~> 4.0.1"

and

gem "gemname", "4.0.1"

and

gem "gemname"

Also what should be used where and benefit of following that way?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
JVK
  • 3,782
  • 8
  • 43
  • 67

1 Answers1

44

The first will tell bundler to load any gem that varies with the last (patch) number. So 4.0.x where x is 1 or greater.

The second will only load 4.0.1.

The third will get the highest value that works (depending on what the needs of the rest of your gems in your Gemfile) or will get whatever is specified in your Gemfile.lock, if you have one.

I missed your second question. Frankly, it depends. For the most part, I go with the first option, because it lets me pick up bug fixes without worrying about how it impacts my other gems.

Dave Powers
  • 2,051
  • 2
  • 30
  • 34
traday
  • 1,151
  • 11
  • 21
  • 1
    Thank you for answering first part. What about 2nd part of the question: Also what should be used where and benefit of following that way? What is the best practice? – JVK Aug 25 '12 at 22:42
  • @JVK refer this post for more details. http://stackoverflow.com/questions/9265213/should-i-specify-exact-versions-in-my-gemfile. – Mukesh Singh Rathaur Jan 20 '14 at 13:25