Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use different versions of a gem at the same time

Can I use two versions of a gem in one application?

I'm trying to use two Rails plugins to work together:

  • Pengwynn's LinkedIn for LinkedIn API calls, has an dependency on OAuth (~> 0.3.5)
  • OmniAuth for user login via multiple well-known websites, has an dependency on OAuth 0.4.0

When I try something in Rails I get this error message:

$ rails server
c:/Ruby187/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/resolver.rb:129:in `resolve': Bundler could not find compatible versions for gem "oauth": (Bundler::VersionConflict)
  In snapshot (Gemfile.lock):
    oauth (0.4.4)

  In Gemfile:
    linkedin depends on
      oauth (~> 0.3.5)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

Trying bundle update freezes my terminal.

Is it possible to use both plugins at the same time?

like image 622
Harm de Wit Avatar asked Dec 02 '10 09:12

Harm de Wit


People also ask

How do I install specific versions of gems?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

How do I update a gem to a specific version bundle?

The correct way to update the version of a gem to a specific version is to specify the version you want in your Gemfile, then run bundle install . As for why your command line was failing, there is no -version option.

What is the difference between gem install and bundle install?

Almost seems like running 'gem install' adds it to the global available gems (and hence terminal can run the package's commands), whereas adding it to the gemfile and running bundle install only adds it to the application. Similar to npm install --global. that's basically it.


1 Answers

Using two versions of a single gem usually means: use two versions of the same class.

It's not possible without making modifications to these gems. You may try to place created classes in some module, resolve conflicts in methods imported into other classes, and so on. In general, it is not easy task, and usually the effect is not worth it.

What you should do in such cases is to ask the gem maintainers to update the dependencies, or try to do it yourself.

Maybe you can downgrade (use older version of) one of these gems, to the version in which the dependencies were the same.

like image 163
Arsen7 Avatar answered Sep 28 '22 10:09

Arsen7