Skip to content

Instantly share code, notes, and snippets.

@arielpontes
Last active May 14, 2024 18:03
Show Gist options
  • Select an option

  • Save arielpontes/b2d783fde85e1b3237b8 to your computer and use it in GitHub Desktop.

Select an option

Save arielpontes/b2d783fde85e1b3237b8 to your computer and use it in GitHub Desktop.
How to use two versions of Vagrant on a Mac

How to use two versions of Vagrant on a Mac

Vagrant doesn't make it easy to manage multiple versions of it. I was lucky enough to ended up working on a project whose vagrant up only works with the legacy Vagrant 1.4 and another one that only works with newer versions. I'll explain here how I managed to keep both. In this case I'll install Vagrant 1.4.3 and 1.7.4 (the newest as of now), but in principle it should work with other versions as well.

Vagrant 1.4.3 doesn't work with newer versions of VirtualBox (>4.3). During this experiment I messed up all my installations several times, so I'm installing everything from scratch (just go to the download page, download the dmg and run the pkg installer normally).

2. Hack the Vagrant 1.4.3 installation

$ sudo mv /Applications/Vagrant /Applications/Vagrant\ 1.4.3
$ sudo ln -Fs /Applications/Vagrant\ 1.4.3/bin/vagrant /usr/bin/vagrant

* This is for legacy Vagrant versions, which are installed in /Applications/Vagrant.

3. Install Vagrant 1.7.4

Vagrant 1.7.4 is organized differently from 1.4.3 and, when running a command that requires application data for the first time (e.g. vagrant box list), it will update its file structure, breaking the 1.4.3 installation. To prevent this from happening, run:

$ sudo mv ~/.vagrant.d ~/.vagrant143.d

* You can run this after installing 1.7.4, just make sure you don't run any vagrant command before.

Now you're safe to install Vagrant 1.7.4. When you're done you can check if everything is ok:

$ rehash
$ vagrant -v
Vagrant 1.7.4

* If you're still getting 1.4.3, just open a new shell.

4. Hack the Vagrant 1.7.4 installation

$ sudo mv /opt/vagrant /opt/vagrant174
$ sudo ln -Fs /opt/vagrant174/bin/vagrant /usr/bin/vagrant

* This is for new Vagrant versions, which are installed in /opt/vagrant.

5. Create shell commands to switch Vagrant

Add these lines to your ~/.bash_profile (or ~/.zshrc or whatever you use):

alias vagrant143='sudo ln -Fs /Applications/Vagrant\ 1.4.3/bin/vagrant /usr/bin/vagrant && mv ~/.vagrant.d ~/.vagrant174.d && mv ~/.vagrant143.d ~/.vagrant.d'
alias vagrant174='sudo ln -Fs /opt/vagrant174/bin/vagrant /usr/bin/vagrant && mv ~/.vagrant.d ~/.vagrant143.d && mv ~/.vagrant174.d ~/.vagrant.d'

That's it!

Now you can easily switch between versions by running vagrant143 or vagrant174:

$ vagrant143
$ vagrant -v
Vagrant 1.4.3
$ vagrant174
$ vagrant -v
Vagrant 1.7.4

Note that your vagrant boxes will be stored separately, so if you add a box while using a version of Vagrant it won't be visible from the other version:

$ vagrant143
$ vagrant box add trusty64
$ vagrant box list
trusty64 (virtualbox)
$ vagrant174
$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.

These are all a bunch of ugly hacks and I can't promise a new Vagrant version won't break it, but for the moment it does the trick for me.

@cogitate

Copy link
Copy Markdown

Thanks a lot for this gist Ariel. You are a life saver.

@navnit

navnit commented Nov 23, 2016

Copy link
Copy Markdown

I need to use Vagrant 1.8.1 and 1.8.7(Latest) together. How to achieve it?

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