Vagrant, What is that?

Ahmad Kamil Almasyhur
4 min readApr 3, 2019

--

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the “works on my machine” excuse a relic of the past.

source: Vagrant Workflow

Vagrant is an automation tool with a domain-specific language (DSL) that is used to automate the creation of VMs and VM environments.

What is VM?

Virtual Machine (VM) is an abstraction so that you can have another guest operation system at top of your host operating system by the help of hypervisor. If you are confused what is host operating system? that is your own OS inside your machine. In another hand the guest operating system is an operating system that runs above your host operating system, let's see this picture if you are confused.

2 VMs showed by green and yellow color as they have their own OS.

How Vagrant able to make VM?

Vagrant needs another provider like VirtualBox, VMware, or any other provider. So that vagrant able to make this “magic” as a provisioner of VMs, making guest OS at top of host OS. As far as I know Vagrant cannot work without a provider, so that’s why you need to install one of supported provider that listed here.

How does Vagrant work?

If you want to use vagrant, you can download it from this link. Then after you download it, you can make a new folder to make sure that you have your own work station of vagrant, then run vagrant init command in your terminal inside that new folder to make a “Vagrantfile”. Then after that, you can specify a box inside vagrant configure config, by using this command config.vm.box = "ubuntu/xenial64" like shown on this page. Wait, what is a box? hmm...

What is a Box?

A box is the predefined images that are used by Vagrant to build the environment according to the instructions provided by the user. A box may be a plain OS installation, or it may be an OS installation plus one or more applications installed. Boxes may support only a single provider or may support multiple providers (for example, a box might only work with VirtualBox, or it might support VirtualBox and VMware Fusion). You can find your own boxes from this link.

How can Vagrant help you to automate the creation of VMs

Let say that you already make that Vagrant file using vagrant init like what I said before. Then if you want to make another VM, you can just type vagrant up from your terminal and wait for maybe 1–5 minutes (it depends on your hardware), and you will able to use that VM terminal by using this command vagrant ssh.
Oh wait, I forgot to say that you are able to predefine your VM, by installing some software when you do vagrant up, you can install git, ruby, java, or other software by using the terminal command. Vagrant already specifies that you can configure your VM, like in this page when you create the VM, you can install some software. So when you run vagrant up , and you then you run vagrant ssh , you will already have that software installed that you predefine it in “Vagrantfile”.
Then, isn’t it hard to do vagrant ssh every time I want to work on something? Can I just work and change the code on my host, then I run it on my guest? of course, you can! you can mount your host folder to your guest, or let say that you can sync your host folder with your guest folder like what vagrant has explained in this page.

Finally, by using vagrant up your excuse about this worked on my machine is just a relic of the past. And you able to work in a machine, that will work everywhere, every time and have the same configuration all the time.

Vagrant command you need to know:

  1. Vagrant init — to create Vagrantfile
  2. Vagrant box — to manage boxes in your local / host
  3. Vagrant up — to create and provision the VM
  4. Vagrant reload — to restart your VM
  5. Vagrant ssh — to connect with the VM using SSH
  6. Vagrant suspend — to suspend your VM
  7. Vagrant resume — to resume your VM after you suspend it
  8. Vagrant halt — to shut down the VM
  9. Vagrant destroy — to delete the VM
  10. Vagrant status — to know the status of your VM

Source:

--

--