Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "~> 4.0.1", "4.0.1" and no version specifier in a Gemfile? [duplicate]

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?

like image 707
JVK Avatar asked Aug 25 '12 21:08

JVK


People also ask

How do I specify a Gemfile version?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

What is the meaning of ~>?

In other words: ~> means it will only allow that specific version, and newer sub-versions in the last decimal.

What is Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

What is Gemspec in Gemfile?

Gemspec is basically the Readme for gems. It tells you about the author, version, summary, description, internal dependencies, execution and everything about the Gem.


1 Answers

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.

like image 115
traday Avatar answered Oct 06 '22 00:10

traday