Appendix A. Vagrant Environmental Variables

There are a handful of environmental variables you can set to control various aspects of Vagrant on your system. These environmental variables all have their uses, which are explained along with their function.

VAGRANT_CWD

VAGRANT_CWD can be set to change the working directory of Vagrant. By default, Vagrant uses the current directory you’re in. The working directory is important because it is where Vagrant looks for the Vagrantfile. It also defines how relative paths in the Vagrantfile are expanded, since they’re expanded relative to where the Vagrantfile is found.

This environmental variable is most commonly set when running Vagrant from a scripting environment.

As a simple example, if you wrote a bash script to bring up multiple Vagrant environments, it might look like this:

#!/usr/bin/env bash

VAGRANT_CWD=/foo vagrant up
VAGRANT_CWD=/bar vagrant up

VAGRANT_HOME

VAGRANT_HOME can be set to change the directory where Vagrant stores global state. By default this is set to ~/.vagrant.d, which is the .vagrant.d folder in your home folder.

The Vagrant home directory is where things such as boxes are stored, so it can actually become quite large on disk.

There are two common use cases for this environmental variable.

First, some people have small solid state drives as their main filesystem for speed, but also have a much larger, slower drive attached for larger files where speed doesn’t matter as much. In this case, to save disk space on the expensive ...

Get Vagrant: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.