Ruby on Rails

How to install and bundle your rails application with a specific bundler version

This minipost will guide you on how to install a new version of bundler, how to bundle a rails application with a specific bundler version and how to update bundler on a project that is already bundled with another version.

How to install and uninstall a specific bundler version to the development machine

Before we start, read this to avoid installing bundler documentation for new versions. In order to get a list all the already installed versions of bundler in your system, type:

$ gem list bundler

A typical output, depending on the bundler versions you have already installed, could be the following:

*** LOCAL GEMS ***

bundler (1.17.1, 1.16.6, 1.16.5)

Now, let's say we want to install version 2.0.1, type:

$ gem install bundler -v 2.0.1
Fetching: bundler-2.0.1.gem (100%)
Successfully installed bundler-2.0.1
1 gem installed

To uninstal this specific version, type:

$ gem uninstall bundler -v 2.0.1

How to bundle an application with a specific bundler version

To bundle an application with a specific bundler version, type:

$ bundle _2.0.1_ install

If you try the above command on an existing project that was bundled with another bundler version specified in Gemfile.lock, you might get an error similar to the following:

Traceback (most recent call last):
    2: from /home/devmachine/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
    1: from /home/devmachine/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/home/devmachine/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': Could not find 'bundler' (1.17.1) required by your /home/devmachine/tested/tested_two/Gemfile.lock. (Gem::GemNotFoundException)
To update to the lastest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.17.1`

In this case just remove from your Gemfile.lock the version of bundler that appears on this part:

BUNDLED WITH
   1.17.1

(just remove only the version you have there, only 1.17.1, leave the BUNDLED WITH part)

And then run again:

$ bundle _2.0.1_ install

You will see that your Gemfile.lock was altered with the new bundler version, that will be used from now on at your Rails application.

Buy Me A Coffee

Read also the following