捆绑执行程序应该找到全球的宝石吗?

时间:2019-06-05 16:06:31

标签: ruby-on-rails ruby debugging visual-studio-code bundler

Visual Studio代码启动配置(并不很重要)试图通过以下方式启动rdebug-ide

bundle exec rdebug-ide

这仅在我将宝石添加到Gemfile时有效。

捆绑执行程序是应该只查找包含在Gemfile中的二进制文件,还是应该全局安装的二进制文件,例如gem install rdebug-ide,也可以从包执行程序访问吗?

这可行:

> rdebug-ide
Using ruby-debug-base 0.2.2 ...

但这不是

> bundle exec rdebug-ide
Gem::Exception: can't find executable rdebug-ide for gem ruby-debug-ide. ruby-debug-ide is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

甚至可以使用!

> bundle exec ls
Gemfile app ...

其他信息:我正在使用rbenv,也许这会以某种方式影响捆绑程序的行为

更新

@tadman指出捆绑软件执行程序正在改变路径。但正如我期望的那样,它似乎正在扩展它,而不是删除任何东西

$ diff <(gem env) <(bundle exec gem env)
24a25
>      - /Users/eng/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/bin

$ which rdebug-ide
/Users/eng/.rbenv/shims/rdebug-ide

$ bundle exec rdebug-ide
bundler: failed to load command: rdebug-ide 
(/Users/eng/.rbenv/versions/2.5.3/bin/rdebug-ide)
Gem::Exception: can't find executable rdebug-ide for gem ruby-debug-ide. ruby-debug-ide is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

此外,路径在其中:

 $ bundle exec gem env | grep $(dirname $(which rdebug-ide))
 - /Users/eng/.rbenv/shims

我倾向于认为rbenv在某种程度上弄乱了事情。

1 个答案:

答案 0 :(得分:0)

bundle exec做很多事情,主要是改变Gem环境,但最重要的是,它改变了您对PATH可执行文件的搜索。

仍然有许多类似ls的Ruby,但是如果Gemfile中不包含gem可执行文件,则它们可能会被剔除。

检查:

bundle exec gem env

与以下内容进行比较:

gem env

您会在“外壳路径”部分看到许多更改。