0

I have two Sinatra apps, each using a different set of gems, and some of them have conflicting versions, e.g. app A uses Nokogiri 1.6.3 and app B uses Nokogiri 1.5.5.

How do I manage those two environments on the same OSX machine and be able to switch between them without conflicts?

Can I use only Bundler for that, or will I also need RVM? How exactly?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
NightOwl
  • 1,069
  • 3
  • 13
  • 23

2 Answers2

4

Bundler Handles Multiple Gem Versions on System

Bundler can handle this use case just fine. Your explicit gem dependencies go into your Gemfile, and all gem versions within the bundle are then stored in the Gemfile.lock file.

As a general rule, your gems will be installed in GEM_HOME. Multiple versions of a gem can be installed at the same time, and require bundler/setup takes care of ensuring that the correct versions (as specified in your Gemfile.lock) are made available to your Ruby application.

However, unless you use binstubs, gemsets, or special invocations like <gem> _<version>_ [args], you will need to run bundle exec <gem> from the command line in order to use the correct version as specified by your bundle.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
  • thanks. I prefer using Bundler. so if my two apps are suing different versions of the same Gem - would they be installed and stored separately on my system? do you know where (i.e. file path)? – NightOwl Aug 05 '14 at 16:15
  • 1
    @NightOwl well looks like someone just asked a question for you http://stackoverflow.com/questions/25143714/does-bundle-install-install-all-the-required-gems-on-my-computer-permanently :) – Mandeep Aug 05 '14 at 16:40
  • @Mandeep I'd expand on that answer and make the command `bundle install --binstub --path vendor/bundles`, get everything project-local. – ian Aug 06 '14 at 00:38
2

The best way to manage multiple applications on a system is to use a manager like RMV (Ruby Version Manager).

RVM has the concept of a gemset, which you can use to create different sets of gems for different apps. It is the solution of your problem. You will need to create different gemsets for both applications. Like this, your gem versions will not conflict.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
RAJ
  • 9,697
  • 1
  • 33
  • 63