What is the difference between ~ and = when specifying rubygem in Gemfile?
That's a pessimistic version constraint. RubyGems will increment the last digit in the version provided and use that until it reaches a maximum version. So ~>0.8.5
is semantically equivalent to:
gem "cucumber", ">=0.8.5", "<0.9.0"
The easy way to think about it is that you're okay with the last digit incrementing to some arbitrary value, but the ones preceding it in the string cannot be greater than what you provided. Thus for ~>0.8.5
, any value is acceptable for the third digit (the 5) provided that it is greater than or equal to 5, but the leading 0.8 must be "0.8".
You might do this, for example, if you think that the 0.9 version is going to implement some breaking changes, but you know the entire 0.8.x release series is just bugfixes.
However, simply using ">=0.8.5"
would indicate that any version later than (or equal to) 0.8.5 is acceptable. There is no upper bound.
Different versions of the same gem in Gemfile - possible?
No, It is disallowed in bundler
Make bundler use different gems for different platforms
This is a known issue in Bundler. The workarounds are either:
- Generate a Gemfile.lock on a system similar enough to your production environment that you get results that match your production platform. Effectively, that means you can only generate the Gemfile.lock file on Windows if your production system is Windows.
- Don't commit a Gemfile.lock file at all, and determine dependencies on the production machine at deploy time (
bundle install
without--deploy
). While not recommended in general, this is an often-used workaround until the bug is fixed. For example, this is the recommended solution offered by Heroku. - Switch to JRuby, which would have the same platform string across both Windows and Linux (
java
). I don't recommend this seriously, but I believe it would fix the problem. - Fix the problem in the Bundler source code, i.e., help the Bundler team fix the bug. :)
Difference between bundle and gem install?
I'd say: by default on your local machine, no particular difference but...
The purpose of bundle install
is to setup everything for the application containing the Gemfile
. You can even pass arguments to make needed gems installed in whatever folder you want.
This way in production, you have clearly separated apps with their own gems.
On the other side, gem install gmaps4rails
(easy advertisement) gets the gem installed for your whole environment.
Can you have multiple versions of a gem in a Gemfile?
You can set an intervall of allowed gems
gem 'rack', '<1.3.3', '>1.2.4'
It will load the most actual one inside the selected intervall.
But I don't think you can require different gem versions.
If a gem would be loaded in different versions, each class and module must get it own namespace to avoid to overwrite the methods of the gem.
When do bundler update the gem incase of gems pointed to git repo?
You do not need to change the version inside the gem every time you make a change to it. When using git gems, Gemfile.lock
locks to a commit hash rather than the version number. You don't need to specify a version at all.
When you run bundle update mygem
and mygem
is a git gem, it will update the locked commit hash to the latest available on the branch you have specified (or on master
if you have not specified a branch).
What is the difference between bundle and bundle update?
In a nutshell: bundle install handles changes to the Gemfile and
bundle update upgrades gems that are already managed by Bundler.
http://viget.com/extend/bundler-best-practices
Needless to say that bundle
and bundle install
are the same command, install
is the default option for bundle
.
Related Topics
Problem Installing SQLite3-Ruby!
Uploading Files in Ruby on Rails
Ruby/Pgsql Error on Rails Start:Cannot Load Such File -- Pg_Ext (Loaderror)
Match Sequences of Consecutive Characters in a String
How to Access Cookies from Applicationcontroller (Rails)
How to Sanitize Raw SQL in Rails 4
Determining Which Rubygem You'Re Using
Using Nokogiri to Split Content on Br Tags
Ruby What Class Gets a Method When There Is No Explicit Receiver
How Might I Simulate a Private Browsing Experience in Watir? (Selenium)
How to Serialize an Object Using Tcpserver Inside
How to Setup a Local Ssl Certificate and a Rails Application
Failed to Build Gem Native Extension - Extconf.Rb Not Found
Ruby 2.7 Says Uri.Escape Is Obsolete, What Replaces It
Splitting Routes File into Multiple Files
Slicing Params Hash for Specific Values
How to Access the Current Node from a Library in a Chef Cookbook