Skip to content

Instantly share code, notes, and snippets.

@petems
Created November 13, 2013 13:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petems/7449151 to your computer and use it in GitHub Desktop.
Save petems/7449151 to your computer and use it in GitHub Desktop.
Check Vagrant version
MIN_REQUIRED_VAGRANT_VERSION = '1.2.1'
if Vagrant::VERSION < MIN_REQUIRED_VAGRANT_VERSION
$stderr.puts "ERROR: We require Vagrant version >=#{min_required_vagrant_version}. Please upgrade. http://downloads.vagrantup.com/\n"
exit 1
end
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.hostname = 'foo'
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
end
@timschumi
Copy link

Although this is probably years old at this point, it should be noted that this version check appears to do lexicographical comparison. For example, this results in 2.2.10 being handled as if it were an earlier version than 2.2.6 (for example).

I don't know when this was added (or if it was always there), but Vagrant now has their own function for checking the version:

if Vagrant.version?("< 1.2.1")
    ...
end

@petems
Copy link
Author

petems commented Sep 18, 2020

Yeah, this is pretty old at this point (2013?), I think this pre-dates the Vagrant.version? method:

I later found that version comparisons in Ruby are fairly simple to do with the Gem library as well:

Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(MIN_REQUIRED_VAGRANT_VERSION)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment