How to Solve Error can’t find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

Posted on

Introduction

The title of this article is actually a real error message. After executing a command, several output appears. The error is part of those output. The executed command is the ‘bundle install’ command. The following is the actual output of that command execution :

root@hostname:/opt/metasploit-framework# bundle install
Traceback (most recent call last):
    2: from /usr/local/bin/bundle:23:in `'
    1: from /usr/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/usr/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
root@hostname:/opt/metasploit-framework#

The above output is the process of an application installation. It is the installation of metasploit framework. First of all, after launching the command, the ‘bundle’ tool will search for the Gemfile.lock in the current working directory. After successfully discover the file, it will read the file. The file itself defines the lists of all the necessary gems for installation. The term ‘gem’  refers to the package, module or application in Ruby programming language. In order to install several gems, the ‘bundle’ tool is very important. It acts as a Ruby dependency package manager. It will search, download and install all of the necessary gems which is listed in the file.

Actually, metasploit framework is completely written in Ruby programming language since 2007.  So, in order to install metasploit framework, it needs several ‘gems’ to be available.  All of the necessary gems is listed in the Gemfile.lock file. It is located in the root folder of the metasploit framework source installer. Therefore, ‘bundle’ is important to perform this task for installing several ‘gems’. In the end, if all the gems has been successfully installed, it will automatically install metasploit framework.

Checking the environment

First of all, to solve the above problem, check the existing environment of the server. The following are steps for checking the environment of the operating system :

1. First of all, check the ruby version :

root@hostname:~$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
root@hostname:~$

2. Next, check the bundle version :

root@hostname:~# bundle --version
Bundler version 2.0.1
root@hostname:~#

3. Continue on the previous step, try to list all the available bundler in the system :

user@hostname:/opt/metasploit-framework$ gem list bundle

*** LOCAL GEMS ***

bundle (0.0.1)
bundler (2.0.1)
user@hostname:/opt/metasploit-framework$

4. Probably the most complete information about gem is available by typing the following command :

root@hostname:/opt/metasploit-framework# gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-linux-gnu]
  - INSTALLATION DIRECTORY: /var/lib/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /root/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /usr/bin/ruby2.5
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /root/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /var/lib/gems/2.5.0
     - /root/.gem/ruby/2.5.0
     - /usr/lib/x86_64-linux-gnu/rubygems-integration/2.5.0
     - /usr/share/rubygems-integration/2.5.0
     - /usr/share/rubygems-integration/all
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /snap/bin
     - /root
     - /opt/postgresql-10.5/app/bin
root@hostname:/opt/metasploit-framework#

Solution

As the information presents in the previous section, actually there is a ‘bundler’ tool. The available version of the ‘bundler’ tool is ‘2.0.1’. But the execution of the command ‘bundler’ fails. It is having a trouble to find the bundler gem itself. Although the ‘bundler’ tool is actually exist in the system, typing the command generates an error state that the gem bundler is not available. Try to check the Gemfile.lock file where it can be the source of the problem. Because it describes all the available gems for installation of metasploit framework. Fortunately, there is an entry in the Gemfile.lock as follows :

BUNDLED WITH
   1.17.3

The Gemfile.lock define the bundler is the ‘1.17.3’. But the available version in the system is ‘2.0.1’. So, just edit the Gemfile.lock file by removing the above lines. Thus, since there is no definition of the bundler version in the Gemfile.lock, it will use the default version of the available bundler in the system.

6. Finally, test the command again. By typing the previous command as follows :

root@hostname:/opt/metasploit-framework$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Following files may not be writable, so sudo is needed:
  /usr/local/bin
  /var/lib/gems/2.5.0
  /var/lib/gems/2.5.0/build_info
  /var/lib/gems/2.5.0/cache
  /var/lib/gems/2.5.0/doc
  /var/lib/gems/2.5.0/extensions
  /var/lib/gems/2.5.0/gems
  /var/lib/gems/2.5.0/specifications
Fetching rake 12.3.2
...

At last, the command is finally working.

Leave a Reply