Is it possible to have two versions of Vagrant in Mac OS X?

2

in my company we are using Vagrant 1.3 and I cannot update it because the Vagrant files we are using in our development environment are tied to that version, and they won't work anymore.

I am thinking about installing the new version of Vagrant in a different folder, but I don't know how to do it and if it would work. I need to use Laravel Homestead, which is only compatible with vagrant 1.6 onwards...

Any ideas? Thank you

(I am using Max OS X 10.10.1 Yosemite)

itsjavi

Posted 2014-12-18T10:58:27.810

Reputation: 123

Answers

2

I also have a similar problem. I need 1.4.3 and can't update to 1.7.4. After a lot of experiments I think I found a solution. It involves some ugly hacking but it did the trick for me. I wrote a gist describing how I did it:

https://gist.github.com/arielpontes/b2d783fde85e1b3237b8

Let me know if it works for the versions you want :)

[ UPDATE ] Here's a copy/paste from the instructions in the gist:

1. Install VirtualBox 4.3 and Vagrant 1.4.3

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.

Ariel

Posted 2014-12-18T10:58:27.810

Reputation: 136

Hi Ariel, glad you found a solution. Could you perhaps post the solution (or a summary of it) here? That way all the necessary info about the problem and its solution is contained in the same page. Thanks! – bertieb – 2015-08-25T09:24:41.287

thanks Ariel! my company finally ugraded to 1.7 but I like your solution – itsjavi – 2015-09-11T15:22:31.823