Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bundle install gemfile with specific version of bundler

I am trying to bundle install a project running gem 'rails', '4.2.0'. Running Bundle install, I get :

Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    rails (= 4.2.0) was resolved to 4.2.0, which depends on
      bundler (>= 1.3.0, < 2.0)

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

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

Thus I then try to install bundler v 1.3.0 to successfully bundle this gemfile : gem install bundler -v 1.3.0

gem list bundler shows me that I successfully installed bundler at v 1.3.0

Then when trying to bundle install with v 1.3.0 like this bundle _1.3.0_ install, I get Could not find command "_1.3.0_".

How can I successfully run bundle install with that specific version of bundler ?

like image 609
David Geismar Avatar asked May 19 '20 18:05

David Geismar


People also ask

How do I specify the bundler version of Gemfile?

The version of bundler that's used is the one that's available in your current ruby environment. The best way to manage this is with gemsets - you can create a gemset with a known, working version of bundler and always switch to that gemset when working with that project.

What is the difference between bundle install and bundle update?

lock . In general, you should use bundle install(1) to install the same exact gems and versions across machines. You would use bundle update to explicitly update the version of a gem.


Video Answer


2 Answers

Basically, you need:

  1. Bundler (>= 1.3.0, < 2.0) installed on your local machine.
  2. Ability to run that Bundler version.
  3. Run that Bundler version to install other gems required by your app (bundle install).

First, check if you have successfully install Bundler (>= 1.3.0, < 2.0) on your local machine:

$ gem list bundler 

You should see:

*** LOCAL GEMS ***
bundler (2.1.4, 1.17.3, 1.3.0)

If not, install it:

$ gem install bundler -v "<2" -N
# Install lasted bundler below version 2
# -N: No document

Second, check if you can run that Bundler version:

$ bundle _1.17.3_ -v

You should see:

Bundler version 1.17.3

If you installed Bundler 1.17.3 but cannot run "bundle 1.17.3 -v", there is something wrong with your RubyGems gem. Check if you installed updated version (latest is 3.1.3):

$ gem -v

Try to update the RubyGems gem, because it is the one help you run a specific gem version:

$ gem update --system

You should see:

Updating rubygems-update
...
Installing RubyGems 3.1.3
Successfully built RubyGem
    Name: bundler
    Version: 2.1.4
    File: bundler-2.1.4.gem
Bundler 2.1.4 installed
RubyGems 3.1.3 installed
Regenerating binstubs
...
------------------------------------------------------------------------------
RubyGems installed the following executables:
    /home/lqt/.rbenv/versions/2.7.1/bin/gem
    /home/lqt/.rbenv/versions/2.7.1/bin/bundle
...
RubyGems system software updated

Check again if you can run a specific Bundler version:

$ bundle _1.17.3_ -v

If you see:

Bundler version 1.17.3

Then, step 3, just run Bundler 1.17.3 to install other gems:

$ bundle _1.17.3_ install
like image 97
lethang7794 Avatar answered Nov 12 '22 06:11

lethang7794


you can try to add this to your Gemfile,

gem 'bundler', '1.17.1'

then try these commands:

gem install bundler -v 1.3.0
gem uninstall bundler -v 2.1.4
bundle update --bundler
bundle install
like image 29
邵俊达 Avatar answered Nov 12 '22 06:11

邵俊达