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:

export VAGRANT_HOME=X:\PATH\TO\VAGRANT

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:

set VAGRANT_HOME=X:\PATH\TO\VAGRANT

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
  • Mu

    hmmm, i get “command export not found”…

  • harveyramos

    If you’re using a regular command prompt, try downloading Bash (options here: http://superuser.com/questions/608106/how-can-i-use-a-bash-like-shell-on-windows). If you’re using Git, I like the Git Bash that comes with it, and is what I usually use.

  • Jaime Olmo

    Export is used in Linux/Unix environments. The equivalent command in windows is SET.

  • harveyramos

    Thanks @jaimeolmo:disqus I’ve updated the post with that info

  • António Pinto

    If you need the VAGRANT_HOME to stay across sessions (usually you would want to keep it saved) you can do a SETX command on the windows cmd or powershell (you need to run it as admin).

    on CMD (Command Line) do:
    setx VAGRANT_HOME “X:/your/path”
    (the ” are important most of the time”)

    if you are using PowerShell you need to call a cmd command with cmd /c COMMAND:
    cmd /c setx VAGRANT_HOME “D:/dev/Vagrant/”
    (the ” are important most of the time”)

    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

    Also, you can check the registry (WinKey+R and type: regedit) at: HKEY_CURRENT_USER/Environment you should see a VAGRANT_HOME key if you added using SETX command, or you can add it manually here by doing:
    – Right Click on the right panel, select New->String Value and name it VAGRANT_HOME.
    – Add your path to the value you added on the previous step.

    Hope this helps :)