Bundler: Can't Find Gem Bundler (>= 0.A) with Executable Bundle (Gem::Gemnotfoundexception) During Bundle Install with Gem

Bundler: can't find gem bundler ( = 0.a) with executable bundle (Gem::GemNotFoundException) during bundle install with gem

Bundler version 2 introduced a new feature to automatically use the version of Bundler specified in the Gemfile.lock of your project. Thus, if you have an existing Gemfile.lock with a line like this at the bottom

BUNDLED WITH
1.17.3

Bundler will try to run with a Bundler version < 2.0. Since you just have Bundler 2.0.1 (and Rubygems >= 2.7.0) installed, this fails with this rather unhelpful error message.

To fix this, you could

  • remove the lines from your Gemfile.lock and to use bundler 2.x everywhere from now on, or
  • install a bundler 1.x version with gem install bundler -v '< 2.0' to use the appropriate version as specified by your Gemfile.lock.

More information about this can be found on the Bundler blog.

Elastic Beanstalk: can't find gem bundler ( = 0.a) with executable bundle (Gem::GemNotFoundException)

So here's the programmatic solution to the above problem. Create the below file under .ebextensions/gem_install_bundler.config:

files:
# Runs before `./10_bundle_install.sh`:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/09_gem_install_bundler.sh" :
mode: "000775"
owner: root
group: users
content: |
#!/usr/bin/env bash

EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
# Source the application's ruby, i.e. 2.6. Otherwise it will be 2.3, which will give this error: `bundler requires Ruby version >= 2.3.0`
. $EB_SCRIPT_DIR/use-app-ruby.sh

cd $EB_APP_STAGING_DIR
echo "Installing compatible bundler"
gem install bundler -v 2.0.1

Then when you next eb deploy, the bundler will have been updated to version 2.0.1, and you won't get the above error again.

More information in the docs here:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html

and here:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-files

Last note: Ensure that you either commit these changes before running eb deploy, or stage them and run eb deploy --staged. See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html. I learned this the hard way!

rbenv — 'find_spec_for_exe': can't find gem bundler ( = 0.a) with executable bundle (Gem::GemNotFoundException)

This is how I finally solved this problem:

$ cd /path/to/my/project/
$ gem install bundler -v 1.17.3
$ bundle install

Gem list doesn't show bundler after Successfully installed bundler

The PATH of the root user is likely not the same as the PATH of your current user. Therefore the gem command that root loads will not be the same as the gem command you load as a normal user. This makes sudo gem install save the gems into a different location (the location of the Ruby installation found in the PATH of the root user).

To fix this issue, the most straightforward solution is to force root to use the same gem command by giving it the full path:

sudo `which gem` install ...

Note the use of backticks. Using backticks this way, the command will essentially expand to something like:

sudo /some/path/to/the/user/ruby/installation/bin/gem install ...

To figure out if the gem command of root is different from your default gem command, you can do this:

# As normal user check output of this command
which gem

# ..and compare it to the output of this command
sudo which gem

can't find gem rails - Gem::GemNotFoundException

If you use the command bundle install to install your gems off of a GEMFILE, it will install the gems into your default system location for gems, as outlined in the bundler docs here. After that, you can use bundlers bundle exec command to execute a command in the context of the bundle, as outlined in the docs here. This will ensure that the version of the gem you installed using bundle install is executed.

If you look at the homepage for bundler, which provides an overview of the docs, it states the following:

In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.

However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.

I'm guessing that you run gem which rails in your console, and then run bundle show rails in your console, the default installed rails installation for your system differs from the one installed for your bundle.

You say that you are using rvm for your ruby and gem management. I'm thinking you may not have properly configured it. Trying executing the rvm notes command in your console to ensure that you have addressed all of the required/recommended steps for installation on your OS. You want to ensure that the executables for rvm are the first things included in your path when you run echo $PATH ideally. This will ensure that the gems installed for rvm will be the ones executed when you try executing them without prefixing bundle exec. If rvm notes doesn't give you the hints necessary to accomplish that, then try carefully reviewing the docs for installation on the RVM website.

Problem installing bundler, Says it installs, but then doesn't actually install


rbenv works by inserting a directory of shims at the front of your PATH:

~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin

Through a process called rehashing, rbenv maintains shims in that directory to match every Ruby command across every installed version of Ruby—irb, gem, rake, rails, ruby, and so on.

Shims are lightweight executables that simply pass your command along to rbenv. So with rbenv installed, when you run, say, rake, your operating system will do the following:

  • Search your PATH for an executable file named rake
  • Find the rbenv shim named rake at the beginning of your PATH
  • Run the shim named rake, which in turn passes the command along to rbenv

You messed up your rbenv installation.

1) Remove ruby installation outside rbenv

2) rvm implode

3) Clean up your $PATH env variable from ~/.bash_profile or ~/.bashrc

Remove any $PATH reference pointing to ruby, irb, gem or any folder including those bin executable. Consider commenting any $PATH statement from your bash_profile

# export PATH="$HOME/etc/bin:$PATH"
# leave the statement below
# export PATH="$HOME/.rbenv/bin:$PATH

The $PATH variable includes a list of folders:

echo $PATH
home/fabrizio/.rbenv/shims:/opt/android-studio/bin:~/.scripts/bin

if you run gem in your terminal

any .bin executable file included in home/fabrizio/.rbenv/shims or /opt/android-studio/bin is executable from any location in the terminal. When you run gem, the ruby gem command is executed instead of being intercepted from rbenv, because you installed ruby outside of rbenv.

UPDATE BASED ON YOUR FEEDBACK

You must have followed this step when installing ruby 2.5.0 without rbenv so remove from your ~/.bash_profile or ~/.bashrc the following line

PATH="$PATH:$(ruby -e 'puts Gem.user_dir')/bin"

or any other line which is adding /Users/brianp/.gem/ruby/2.5.0/bin to your $PATH, then uninstall ruby with apt.

Read the following information, additionally always check the location where gems are being installed with gem env:

$ gem env home
# => ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...

if the location from anywhere in the terminal is not under ~/.rbenv/ then you are installing the gems in the wrong locations.

LAST RESORT

Delete the gem folder with rm -rf ~/.gem, a similar approach to this post if you can not remove /Users/brianp/.gem/ruby/2.5.0/bin from your $PATH

SOLUTION FOR YOUR LAST ERROR

This error is caused from installing bundler 2.0

  can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

you need to remove bundler 2.0 and install 1.9.0

Can't find gem railties ( = 0.a) with executable rails (Gem::GemNotFoundException)

try to run
gem install bundler
then run bundle

if you still getting the error then run,

bundle install --path vendor/bundle


Related Topics



Leave a reply



Submit