Search code examples
rubybundler

What is the right way to ensure the correct version of a gem is required using bundler?


If I understand correctly puting

require 'rubygems'
require 'bundler/setup'

at the top of my ruby source file will ensure that subsequent requires will load the versions of the gems specified in the Gemfile located in the same directory, thus allowing me to develop multiple projects which use different versions of the same gem - is this correct? How is this different from using Bundler.setup()?


Solution

  • When you require 'bundler/setup' it loads this file which calls Bundler.setup for you. This means there's no need for you to include that in your own code.

    RubyGems is loaded implicitly by Ruby, unless you're using a really old version, so require 'rubygems' isn't needed.