RVM is set on ruby-2.4.0 & I created new application which have version,

gem 'rails', '4.2.6'

I updated bundler using,

gem update --system
gem install bundler
bundle version
# Bundler version 2.0.1 (2019-01-04 commit d7ad2192f)

But I am getting following error while bundle install,

Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    rails (= 4.2.6) was resolved to 4.2.6, which depends on
      bundler (< 2.0, >= 1.3.0)

  Current Bundler version:
    bundler (2.0.1)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?

Could not find gem 'bundler (< 2.0, >= 1.3.0)', which is required by gem 'rails (= 4.2.6)', in any of the sources.

It is asking me for lower version version of bundler required, why? How should I solve above?

2 Answers

dubadub On Best Solutions

Your Gemfile specifies older bundler version which is not compatible with 2.x.x. Try to run gem install bundler -v 1.3.0 or whatever version you have listed in your Gemfile.lock (check the very end of file).

mechnicov On

Install any bundler with version (< 2.0, >= 1.3.0).

For example

gem install bundler -v 1.17.3

And then

bundle _1.17.3_ install

It should work for your situation.