mitchellh/vagrant-installers — pull request #33 by dpiddy (2014-03-14 02:52:58+00:00)
Title: substrate: Also unset RUBYLIB.

Ref https://github.com/mitchellh/vagrant/issues/3193

Similar to `$RUBYOPT` being in the environment, `$RUBYLIB` can also cause issues. An example scenario where this is a problem for packaged vagrant:

1. I have vagrant installed on OS X via the installer at `/Applications/Vagrant` with its own embedded ruby
1. I have my own version of ruby (such as 2.1.1) installed elsewhere and use that for my work
1. I have a project which has a `Gemfile` that does not contain vagrant. I want to use the version I installed via the installer.
1. In the `Gemfile`, I use a gem, say, test-kitchen, that in turn wants to run vagrant
1. Using my ruby, I run `bundle exec kitchen test`
1. `bundle exec` exports `RUBYOPT=-rbundler/setup` and `RUBYLIB=/opt/boxen/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/bundler-1.6.0.rc/lib`, the latter being valid only for my ruby
1. Eventually test-kitchen runs `vagrant` and by virtue of `$PATH` it really runs `/usr/bin/vagrant`
1. Without this PR, `/usr/bin/vagrant` unsets only `RUBYOPT` which disables bundler autoloading but it does not unset `RUBYLIB`, which is still meant only for my ruby
1. `/usr/bin/vagrant` runs the embedded vagrant with the embedded ruby, still with `RUBYLIB` set
1. The embedded vagrant does `require "bundler"` or similar but finds my version of bundler instead of the embedded version at `/Applications/Vagrant/embedded/gems/gems/bundler-1.5.3`
1. As things are now, my version of bundler is not compatible with the embedded version so things blow up

With this PR, `RUBYLIB` is also unset letting the embedded vagrant's `require "bundler"` find the also-embedded version.

Some more snippets that show the leakage in action and that unsetting `RUBYLIB` fixes it:

```
$ echo > Gemfile
$ bundle install
The Gemfile specifies no dependencies
Resolving dependencies...
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

# `bundle exec` exports these, meant only for my ruby
$ bundle exec bash -c env | egrep ^RUBY
RUBYOPT=-rbundler/setup
RUBYLIB=/opt/boxen/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/bundler-1.6.0.rc/lib

# RUBYLIB affects the embedded ruby as expected
$ bundle exec /Applications/Vagrant/embedded/bin/ruby -e 'puts $:.first'
/opt/boxen/rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/bundler-1.6.0.rc/lib

# since I don't have vagrant in my bundle, it finds the installed packaged version's
# wrapper via $PATH
$ bundle exec bash -c 'which vagrant'
/usr/bin/vagrant

# trying to run via the wrapper breaks due to RUBYLIB being set with a load path
# meant for my ruby, containing my version of bundler
$ bundle exec vagrant
/Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/bundler.rb:31:in `initialize': undefined method `new' for Bundler::UI:Module (NoMethodError)
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/bundler.rb:17:in `new'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/bundler.rb:17:in `instance'
from /Applications/Vagrant/bin/../embedded/gems/gems/vagrant-1.5.0/lib/vagrant/pre-rubygems.rb:22:in `

'

# however, running it again with RUBYLIB unset lets the embedded vagrant setup
# find its also embedded version of bundler
$ bundle exec bash -c 'unset RUBYLIB; vagrant'
Usage: vagrant [options] []
...
```

Hopefully I've done a better job explaining here than in the initial issue. Thanks for vagrant and your help.