From c64a95156d958d12cb0942dc5e7ec89ec848cc36 Mon Sep 17 00:00:00 2001 From: "Z. Cliffe Schreuders" Date: Mon, 30 Jan 2023 17:49:20 +0000 Subject: [PATCH] vagrant executed directly (without gem) --- lib/helpers/gem_exec.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/helpers/gem_exec.rb b/lib/helpers/gem_exec.rb index 295c0cecd..59658e5c7 100644 --- a/lib/helpers/gem_exec.rb +++ b/lib/helpers/gem_exec.rb @@ -14,13 +14,24 @@ class GemExec version = '>= 0' begin - gem_path = Gem.bin_path(gem_name, gem_name, version) + gem_path = "" + # new versions of vagrant are executed directly + # this is the most reliable way of checking for vagrant, when multiple versions are isntalled + if gem_name == 'vagrant' && File.file?("/usr/bin/vagrant") + gem_path = "/usr/bin/vagrant" + end + # test if the program is already installed via package management (for example, vagrant now does this) + if gem_path.empty? + gem_path = `which #{gem_name}`.chomp + end + # otherwise try getting the location of installed gem + if gem_path.empty? + gem_path = Gem.bin_path(gem_name, gem_name, version) + end unless File.file?(gem_path) raise 'Gem.bin_path returned a path that does not exist.' end rescue Exception => e - # test if the program is already installed via package management - gem_path = `which #{gem_name}`.chomp unless File.file? gem_path Print.err "Executable for #{gem_name} not found: #{e.message}" # vagrant can be executed via the gem path, but not installed this way