Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to `bundle install` when your Gemfile requires an older version of bundler?

I am in an older Rails project that has a Gemfile. I tried to add a gem to the Gemfile and bundle install but got an error:

Bundler could not find compatible versions for gem "bundler":   In Gemfile:     rails (= 3.0.0) ruby depends on       bundler (~> 1.0.0) ruby    Current Bundler version:     bundler (1.1.5)  This Gemfile requires a different version of Bundler. 

The version of Rails it's using requires bundler ~>1.0.0 but I have 1.1.5 installed and am using it for my other projects. Usually I would use bundle exec ... but since this is bundler we are talking about, it's a little more complicated than that. How can I add a gem to my Gemfile and run bundle install while using the version of bundler that it requires?

like image 251
Andrew Avatar asked Aug 23 '12 13:08

Andrew


People also ask

How do I change my bundle version?

If you want to upgrade the Bundler version used by your application, you can run bundle update --bundler , and your lockfile will be regenerated using the latest version.

How do I install everything in Gemfile?

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. Save this answer.


2 Answers

First you need to install the appropriate version of bundler:

% gem install bundler -v '~> 1.0.0' Successfully installed bundler-1.0.22 

Then force rubygems to use the version you want (see this post):

% bundle _1.0.22_ install 
like image 133
alexsanford1 Avatar answered Sep 22 '22 21:09

alexsanford1


The error message In Gemfile: bundler (~> 1.16) is a bit inaccurate, since the version number requirement can come from other places, such as the .gemspec file, which was the case for me:

spec.add_development_dependency "bundler", "~> 1.16" 

Removing the version number from the .gemspec file solved the issue for me:

spec.add_development_dependency "bundler" 
like image 45
Asbjørn Ulsberg Avatar answered Sep 26 '22 21:09

Asbjørn Ulsberg