I need to ensure some of my gems are installed from our own gem repository rather than rubygems, while the rest are installed from rubygems. Can I set this up in the Gemfile without worrying about a naming conflict with a identically named gem in Rubygems? How Can I determine where the gem is downloaded from?
eg Gemfile:
source :rubygems gem 'gemfromrubygems1' gem 'gemfromrubygems2' source "http://our.own.gem.repo.com/the/path/to/it" gem 'gemfromourrepo'
run the command bundle install in your shell, once you have your Gemfile created. This command will look your Gemfile and install the relevant Gems on the indicated versions. The Gemfiles are installed because in your Gemfile you are pointing out the source where the gems can be downloaded from.
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.
The Gem Development guide says that the Gemfile. lock file "should always be checked into version control." However, this is NOT true for Gems. For Applications, like your Rails apps, Sinatra apps, etc., it is true. The same does not go for Gems.
A Gemfile is a file we create which is used for describing gem dependencies for Ruby programs. A gem is a collection of Ruby code that we can extract into a “collection” which we can call later. It lets you specify which gems you want to use, and which versions of these gems to use.
Bundler 1.7 has a new feature that allows you to select the source for specific gems by nesting them in a block:
source "https://rubygems.org" gem 'gemfromrubygems1' gem 'gemfromrubygems2' source "http://our.own.gem.repo.com/the/path/to/it" do gem 'gemfromourrepo' end
or specifying it as an option:
source "https://rubygems.org" gem 'gemfromrubygems1' gem 'gemfromrubygems2' gem 'gemfromourrepo', source: "http://our.own.gem.repo.com/the/path/to/it"
See http://bundler.io/v1.7/gemfile.html for details.
According to the Source Priority section in the Gemfile manpage sources are searched from last entered to first entered.
Based on what you said, it sounds like you want to always prefer your gem over rubygems.org
. As long as you don't need to vary your preference (ie. some dups from rubygems.org
and some dups from your private repo) then your problem is solved simply with the following Gemfile
:
source 'https://rubygems.org' source 'http://our.own.gem.repo.com/the/path/to/it' gem 'gemfromrubygems1' gem 'gemfromrubygems2' gem 'gemfromourrepo'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With