Vagrant is a wrapper for VirtualBox. It allows you to interact with your virtual box using a
Vagrantfile and a set of commands, similar to Docker.
To use Vagrant, you will first need to install VirtualBox: https://www.virtualbox.org/wiki/Downloads
Install Vagrant from here: https://learn.hashicorp.com/tutorials/vagrant/getting-started-index?in=vagrant/getting-started
Getting Started & Basic Commands ¶
To create a box:
vagrant init <BOX_NAME>
vagrant init ubuntu/trusty64
To run the box:
To shut down the box:
To resume the box:
To remove the box permanently:
If you update your
Vagrantfile and want to reload:
SSH into Box ¶
You can SSH into your box:
This will bring up a terminal that you can use. For example, you might want to install git:
sudo apt-get update sudo apt-get install -y git
Memory and CPU Settings ¶
To configure memory and CPU used by your virtual box:
config.vm.provider "virtualbox" do |vb| vb.memory = 2048 vb.cpus = 4 end
Folder Settings ¶
You will probably also want to use data from your local machine. To do this:
config.vm.synced_folder "path/to/local/folder", "path/to/vagrant/folder"
path/to/local/folder can be absolute, or relative to the location of the Vagrantfile. The
path/to/vagrant/folder is where you want the data to be added in your box.
Startup/Provision Settings ¶
When you start your box, you can install packages/run commands:
config.vm.provision "shell", inline: <<-SHELL apt-get update apt-get install -y apache2 SHELL
If you have a lot of packages to install or commands to run, you may want to put them in a separate file:
config.vm.provision "shell", path: "install.sh"
Running MacOS ¶
In order to run MacOS, you may need to reinstall.
sudo su csrutil clear reboot
2. Uninstall from the official installer (you may have to re-download the installer if you deleted it, as the uninstall file is in there).
4. Restart your computer.
5. Install Oracle VM VirtualBox Extension Pack
vagrant plugin install vagrant-vbguest