`bundle exec` without using gems' binaries

33 views
Skip to first unread message

Reto Kaiser

unread,
Jan 27, 2016, 3:36:12 PM1/27/16
to ruby-bundler
I'm wondering if there's a way to make `bundle exec <binary>` not use binaries of the gems from the bundle.

Sometimes a gem includes library code and a binary, but I would like to use only the library code (and instead use the binary from my default PATH).
I understand bundler prepends the bundle's "bin/" directory to the PATH in "SharedHelpers#set_bundle_environment". Is there a way to avoid it?

For example: "vagrant-librarian-puppet" is a vagrant plugin gem and includes "puppet" as a library dependency. When it shells out to run the "puppet" command it should use the system's puppet, and not the one from the bundle.

Thanks for any input!
 Reto

André Arko

unread,
Jan 27, 2016, 3:37:05 PM1/27/16
to ruby-b...@googlegroups.com
Yes, you should shell out using the `Bundler.with_clean_env` method. For example: `Bundler.with_clean_env { system(“puppet dostuff”) }`.


--
You received this message because you are subscribed to the Google Groups "ruby-bundler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-bundler...@googlegroups.com.
To post to this group, send email to ruby-b...@googlegroups.com.
Visit this group at https://groups.google.com/group/ruby-bundler.
For more options, visit https://groups.google.com/d/optout.

Reto Kaiser

unread,
Jan 28, 2016, 2:24:14 AM1/28/16
to ruby-bundler
Perfect, thanks!
I see it's even in the man page…

Reto

Reto Kaiser

unread,
Jan 28, 2016, 3:52:14 AM1/28/16
to ruby-bundler
Hm, it doesn't work well in my case.

1. Let's say the original PATH is "/bin".
2. Then I run `bundle exec rspec`:
 - ENV's PATH is set to "/ruby/gems/bin:/bin".
 - ORIGINAL_ENV's PATH is set to "/bin"
3. The "rspec" binary is executed, bundler is required again:
 - ENV's PATH is set to "/ruby/gems/bin:/bin" (nothing added because of "uniq")
 - ORIGINAL_ENV's PATH is set to "/ruby/gems/bin:/bin"

At that point obviously there's no way to restore the original environment, because it's already overwritten.

Is this a general issue, or something wrong with my setup?

Regards,
 Reto

Reto Kaiser

unread,
Jan 30, 2016, 8:12:30 AM1/30/16
to ruby-bundler
Ok I've opened a ticket about this, with some more details:
Reply all
Reply to author
Forward
0 new messages