Vagrant#
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.
Tutorial: https://www.youtube.com/watch?v=vBreXjkizgo
Installing #
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>
For example:
vagrant init ubuntu/trusty64
To run the box:
vagrant up
To shut down the box:
vagrant suspend
To resume the box:
vagrant resume
To remove the box permanently:
vagrant destroy
If you update your Vagrantfile
and want to reload:
vagrant reload
SSH into Box #
You can SSH into your box:
vagrant ssh
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
Vagrantfile #
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"
The 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.
Clear
csrutil
and restart.
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).
3. Reinstall.
4. Restart your computer.
5. Install Oracle VM VirtualBox Extension Pack
6. Install vagrant-vbguest
:
vagrant plugin install vagrant-vbguest