2
votes

I was running into an issue with bundler when using rbenv. I had switched from ruby 2.3.1 to 2.5.1 a while ago, but I noticed the following error when trying to run bundler inside of a shell script in an ansible task.

``` rbenv: bundle: command not found

The `bundle' command exists in these Ruby versions:
  2.2.2
  2.3.1

```

I saw some solutions to this where you had to install bundler when on a specific ruby version. However even uninstalling bundler and reinstalling it did not resolve the issue. It seemed due to some gem issue that I could not install bundler on specific ruby versions, thus reinstalling bundler did nothing for me.

2
It is always safe to remove rbenv and all installed rubies, then reinstall from scratch. Strange issues like this are typically resolved by a clean installation.anothermh

2 Answers

1
votes

However I did find a very manual solution to this.

I noticed how rbenv whence bundle specified that bundle was active in some ruby versions, but not others. I tracked down the portion of rbenv whence command to find out where it was looking and saw that it looked under the following path for each ruby version installed under rbenv: ~/.rbenv/versions/$VERSION/bin/

If you look under the path for the gem without bundler (for me this was ~/.rbenv/versions/2.5.1/bin/) you will notice that it is not there. However under other versions that whence can recognise you will see the executable is there (for me it was there under ~/.rbenv/versions/2.3.1/bin/bundle and ~/.rbenv/versions/2.3.1/bin/bundle).

So I copied the executable over from the working ruby version to the one that was broken. Then at the top of the file you will notice sha-bang is set to the other ruby version (for me this was #!/Users/myuser/.rbenv/versions/2.3.1/bin/ruby). Change the version path to the ruby version you want to fix and then it will all magically start working.

0
votes

I would highly recommend that you run your ansible scripts in an environment without rbenv. In other words, it is preferable to be using vagrant or a VM to practice your scripts in.

If your project really needs rbenv, please use the ansible rbenv library to work with it, but running it on your host machine is a dangerous way to develop because it is not easily reversible.

Hope this helps!