rubybundler

How to test if a Ruby script is running via Bundler


In a Ruby script, is there a way to test if the current process has been launched via Bundler - i.e. via bundle exec or a binstub?


Solution

  • You could check defined?(Bundler), but that will also be present if you require 'bundler' without having run bundle exec.

    When you run inside bundle exec, there are a few ENV variables present that aren't otherwise. Notably, BUNDLE_GEMFILE and BUNDLE_BIN_PATH.

    There are some more details in the Environment Modifications section of the bundle exec docs.