I have no idea why this was so difficult. Maybe because I’m n00bsauce.
I have an SSD for my boot drive, which I don’t want filling up with virtual machines. So after following installation instructions for Vagrant I tested it out by downloading Laravel’s Homestead vagrant box. Much to my chagrin, there was no way during the download to specify WHERE I want this file to go.
After some brief googling, I came across many references to VAGRANT_HOME including this one from the Vagrant Docs which should allow me to change the vagrant box directory.
VAGRANT_HOME can be set to change the directory where Vagrant stores global state. By default, this is set to ~/.vagrant.d. The Vagrant home directory is where things such as boxes are stored, so it can actually become quite large on disk.
GREAT. But…. HOW DO I SET THIS?!?!?!?!
More googling, and people just keep saying “set your environment variables”. HOW? Well, after MUCH trial and error (including setting environmental variables in Windows Advanced System Properties, which didn’t work btw) I finally figured it out, and it was super easy.
Open a bash window* and type the following:
Where X is your drive letter, and surely you can figure out the path part. That’s it, you’re done. You may want to avoid folder paths with spaces in it, so K.I.S.S.
Apparently, this only sticks for the current session. So if you want to have this as a default then you need to edit your .bashprofile which will be in your
C:\users\yourusername folder and add that line into it. If you don’t have a .bashprofile file just create it (I used Notepad++) and put that as the only line in it.
* = Whatever you plan on using to run the vagrant commands. Bash or powershell is your best bet, but a simple command prompt will do in a pinch.
UPDATE = Thanks to Jaime in the comments below, use the
SET command in a Windows command prompt instead of
EXPORT to set the environment variable. Like this:
UPDATE #2 = Thanks to Antonio in the comments below, use the
SETX command to permanently set the environment variable so you don’t have to run each time you open a new command prompt. For more details including Powershell and Registry options see the comment here. Many thanks Antonio!
setx VAGRANT_HOME "X:/your/path"
NOTE: This adds to the User Environment, if you want to add to the system/machine you need to add the /M option at the end of the command, for example:
setx VAGRANT_HOME "X:/your/path" /M