Skip to content
This repository has been archived by the owner on May 21, 2020. It is now read-only.

Vagrant Tips and Tricks

Linda Nichols edited this page Jun 6, 2014 · 2 revisions

Vagrant Commands

Vagrant has many commands to control its virtual machine. For a full list, see the official docs here, but here are the most common:

vagrant up This is the command you just ran to boot the box up and provision the server based on the configuration file Vagrantfile. I use this for starting as well as resuming my environments.

vagrant suspend Use this command to “pause” your virtual environment. Make sure you do this before shutting down your computer to safely be able to restore the environment later.

Starting, Pausing, and Resuming: To start or restore the environment you can just run vagrant up. The state will be saved and everything should be where you left it off from including your database changes.

vagrant destroy This permanently removes the virtual environment from your machine.

vagrant reload If your environment suddenly stops working, it’s useful to reboot by running this command. If you add the --provision flag, it will re-provision the box as well.

vagrant ssh If you need to connect to the virtual server, just run this command.

Changing Memory on the Vagrant VM

In the Vagrantfile, this line specifies how much memory is allocated to the Virtual Machine:

v.customize ["modifyvm", :id, "--memory", "4096"]

Using VMWare Fusion instead of VirtualBox

If you want to use VMWare Fusion instead of VirtualBox, use vagrant up --provider=vmware_fusion instead of vagrant up when building the VM for the first time. After that, Vagrant will remember your provider choice, and you won't need to include the provider flag again.

Viewing the Vagrant VM in Gui Mode

In the Vagrantfile, uncomment the following line:

#v.gui = true

Accessing the Vagrant Postgres Database from the Host

Edit pg_hba.conf in the Vagrant VM to allow the host machine access. This command uses Vim, but any text editor will work:

vim /etc/postgresql/9.1/main/pg_hba.conf

Add an entry to allow access to the database:

host    all     all   0.0.0.0/0   trust

The server IP address for the Vagrant database will be the static private IP address of the Virtual Machine: 192.168.33.10