diff --git a/lib/vagrant/command/gem.rb b/lib/vagrant/command/gem.rb index 3eec3b2e3..fe558b1e5 100644 --- a/lib/vagrant/command/gem.rb +++ b/lib/vagrant/command/gem.rb @@ -5,6 +5,16 @@ module Vagrant module Command class Gem < Base def execute + # Bundler sets up its own custom gem load paths such that our + # own gems are never loaded. Therefore, give an error if a user + # tries to install gems while within a Bundler-managed environment. + if defined?(Bundler) + require 'bundler/shared_helpers' + if Bundler::SharedHelpers.in_bundle? + raise Errors::GemCommandInBundler + end + end + # We just proxy the arguments onto a real RubyGems command # but change `GEM_HOME` so that the gems are installed into # our own private gem folder. diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 5e928f07b..71b98ceb5 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -173,6 +173,11 @@ module Vagrant error_key(:environment_locked) end + class GemCommandInBundler < VagrantError + status_code(71) + error_key(:gem_command_in_bundler) + end + class HomeDirectoryMigrationFailed < VagrantError status_code(53) error_key(:home_dir_migration_failed) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 95ecb8a71..1789821df 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -47,6 +47,12 @@ en: may run at any given time to avoid problems with VirtualBox inconsistencies occurring. Please wait for the other instance of Vagrant to end and then try again. + gem_command_in_bundler: |- + You cannot run the `vagrant gem` command while in a bundler environment. + Bundler messes around quite a bit with the RubyGem load paths and gems + installed via `vagrant gem` are excluded by Bundler. + + Instead, please include your Vagrant plugins in your Gemfile itself. guest: invalid_class: |- The specified guest class does not inherit from `Vagrant::Guest::Base`.