Vagrant is an open-source command-line tool developed by Hashicorp, designed to simplify the creation and management of portable development environments. It allows developers to define their desired environment specifications in a configuration file called the “Vagrantfile.” By automating the provisioning of virtual machines based on this file, Vagrant ensures consistent development environments across different systems. It integrates with popular virtualization providers and cloud platforms, making it versatile for various deployment options. With Vagrant, developers can avoid compatibility issues and reduce setup time by sharing standardized environments. It is particularly useful for projects with complex dependencies and collaborative teams, streamlining the development workflow and improving efficiency.
In the following article we will go through the steps to create and configure a virtual machine on the local environment from scratch.
Prerequisites:
- Install a virtualization product such as VirtualBox (Free) , VMware Fusion (Paid), or Hyper-V (Windows only). Follow the links given below for each product.
VirtualBox: https://www.virtualbox.org/wiki/Downloads
Hyper-V: https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/about/
VMware fusion: https://www.vmware.com/in/products/fusion/fusion-evaluation.html
I will suggest to go with Oracle Virtualbox as it is free to use and easy to install as well. - Install Vagrant using the official documentation available at: https://developer.hashicorp.com/vagrant/downloads
Setup:
- Create a directory called “debian” (or choose any name you prefer) and navigate to that directory.
- Run the following command inside the directory to create the default Vagrant configuration file:
vagrant init
- Visit the official Vagrant website at https://app.vagrantup.com/boxes/search to search for the base image you want to use for creating the virtual machine. In HashiCorp terminology, the image is referred to as a “box.”
- In this example, I will use Debian Buster as the base image, so I searched for “debian buster.”
- Copy the Vagrant file content provided below:
Vagrant.configure("2") do |config|
config.vm.box = "debian/buster64"
end
- Replace the following line in the Vagrant file with the copied line:
config.vm.box = "base"
That’s it! We have finished configuring the Vagrantfile. To start the virtual machine, run the following command:
vagrant up
Once the machine is up, use the following command to SSH into it:
vagrant ssh
Congratulations! You are now inside your virtual machine.
To further customize your virtual machine, you can add more parameters, such as configuring a private IP. For example:
config.vm.network "private_network", ip: "192.168.50.4"
For more details about Vagrant, refer to their official documentation website at https://developer.hashicorp.com/vagrant/docs.
Subscribe to this blog to receive more useful articles directly in your inbox.
Leave a comment