Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Bundler multiple sources in Gemfile

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' 
like image 467
mawk044 Avatar asked Apr 18 '13 00:04

mawk044


People also ask

How do I use Gemfile in Ruby?

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.

What is the difference between 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.

Should a gem have a Gemfile lock?

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.

Is Gemfile a Ruby file?

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.


2 Answers

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.

like image 96
Tim Moore Avatar answered Oct 14 '22 11:10

Tim Moore


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' 
like image 23
gtd Avatar answered Oct 14 '22 12:10

gtd