简体   繁体   English

捆绑软件不适用于rbenv,无法通过gem安装捆绑软件

[英]Bundle not working with rbenv and cannot gem install bundler

I was running into an issue with bundler when using rbenv. 使用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. 我之前从ruby 2.3.1切换到2.5.1,但是在尝试在ansible任务中的shell脚本中运行bundler时发现以下错误。

``` rbenv: bundle: command not found rbenv:bundle:找不到命令

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. 我看到了一些解决方案,在特定的Ruby版本上必须安装捆绑程序。 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. 似乎由于某些宝石问题,我无法在特定的ruby版本上安装捆绑软件,因此重新安装捆绑软件对我没有任何帮助。

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. 我注意到rbenv whence bundle如何指定该捆绑软件在某些ruby版本中处于活动状态,而在其他版本中却未激活。 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/ 我跟踪了rbenv whence命令的一部分,以查找它的查找位置,并看到在rbenv下安装的每个ruby版本的查找路径都在以下路径下: ~/.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. 如果您查看不带捆扎器的宝石的路径(对我来说是〜/ .rbenv / versions / 2.5.1 / bin /),您会发现它不存在。 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 ). 但是,在其他可以识别的版本下,您会看到可执行文件在那里(对我而言,它位于~/.rbenv/versions/2.3.1/bin/bundle~/.rbenv/versions/2.3.1/bin/bundle )。

So I copied the executable over from the working ruby version to the one that was broken. 因此,我将可执行文件从有效的ruby版本复制到了已损坏的版本。 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 ). 然后,在文件顶部,您会注意到sha-bang设置为其他红宝石版本(对我来说是#!/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. 将版本路径更改为您要修复的ruby版本,然后它就会神奇地开始工作。

I would highly recommend that you run your ansible scripts in an environment without rbenv. 我强烈建议您在没有rbenv的环境中运行ansible脚本。 In other words, it is preferable to be using vagrant or a VM to practice your scripts in. 换句话说,最好使用vagrant或VM来练习脚本。

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. 如果您的项目确实需要rbenv,请使用ansible rbenv库来使用它,但是在您的主机上运行它是一种危险的开发方式,因为它不容易逆转。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM