Up and running with Vagrant- 6 mins
Recently I was learning about linux environment and for practical learning I need to execute commands or install tools or changing complicated settings like user permission, firewall setup. Performaing this kind of operation on my own machine may led to generate unnecessary files or dangerous problems and I was looking for a different approach to learn and do the both works safely. Then I came up to a solution like Vagrant, which is perfectly suitable for my expectation. So I dig into it and found out that it is not only useful for experimental work but also for some other cases too. Let’s explore what we can do with vagrant and how it can be useful in your case.
What is Vagrant
Vagrant is a mature and stable virtual environment builder. It can be used for building and distributing virtual environments. By environment I mean an OS (like Ubuntu) setup. You can create one environment (aka OS), configure with necessary tools and share the environment. People only need configuration file and when they boot it up they will get exact same environment with same tools in their machine.
Vagrant works on Linux, Mac and Windows. Vagrant also an open source project (Github).
One can set up a platform independent development environment.
Single script for complete environment setup including all necessary software and tools (Using provisioning).
Developers don’t have to setup environment in several places. One can create it with all dependencies and tools and distribute to other team members.
Same environment for development, staging and production.
Creating VM on various cloud providers (including all major ones)
Remote collaboration through vagrant environments.
Has plugins for various feature.
Step 1: Download and install VirtualBox on your machine.
Step 2: Now download and install specific vagrant package/installer for your machine from here.
Step 3: Create a folder in you work directory. Inside that run this command to initialize vagrant.
Here vagrant init initializes a vagrant file with ubuntu/bionic64 ubuntu 18 64 bit box. You can search and use existing boxes from here. You can also build your own box and share here. This will create a new file named Vagrantfile in your directory.
- Step 4: Run this command to execute vagrant file.
This may take few seconds to an hour based on your internet connection speed.
- Step 5: Execute this to enter shell.
- Step 6: If you want to terminate vagrant you can use this commands.
This will completely shuts down the running machine vagrant is managing (source). Or this command
This will not shut down rather just suspend the machin vagrant is managing it. A suspend effectively saves the exact point-in-time state of the machine, so that when you resume it later, it begins running immediately from that point, rather than doing a full boot (source).
How it works
Technology behind vagrant require three basic things:
We’ve already discussed about box in Step 3 of Installation section. You can publish or find existing boxes from here. Box is a packaged virtual environment.
Provider is the location in which virtual environment(Box) runs. It has two types local and remote.
Also an special case Docker can be used as a provider.
To learn more about Vagrant use following resources-
Official Getting started guide.
Vagrant in 5 minutes. watch here
Vagrant crash course by Traversy Media. watch here
So this is my current understanding of vagrant. Feel free to correct me if I did any mistake here or need to add anything.