Beginner guide for Vagrant

Beginner guide for Vagrant

4 min read

Hello, fellow developers ready to set sail in the ocean of DevOps.I am gonna introduce you to the virtual environment tool the VAGRANT . We will cover basic ideologies and concepts of vagrant and go through the installation steps.

What is vagrant?

A vagrant is a management tool for a virtual environment supported across the platform for the development distribution and testing of software in a customizable virtual environment. It uses the virtual box , VMware, and cloud as the service provider for the stimulation of the virtual environment. Base on the Command-line interface(CIF) for simplicity, customization, and providing full control over the core and plugins of the virtual environment. It has 3 essential components the vagrant tool itself, the Vagrantfile for initial state customization, and the Vagrant box which acts as a base on which the developer can build upon as per the need. The boxes are available for all the major operating systems. It is also compatible with all most all the major operating systems.

Vagrant file

It is a configuration file which is referred by the vagrant tool whenever the virtual environment is executed in the host OS. The vagrantfile is written using language Ruby. This file setup configuration for the base box to be imported, it defines the base properties like base os, public and private network configurations and, specific port forwarding, providing the folder location to communicate and share the file with host OS, adding configuration, installing updates, setting public and private network configurations, additional software tools and many more

It serves as the basic configuration for the run time of the virtual environment.

Along with pre-defined configuration, the minimum file with just three lines of Ruby text can be used for setup.

Vagrant.configure("2") do |config| = "ubuntu/bionic64"

Example2: Standard Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below.
Vagrant.configure("2") do |config| = "ubuntu/bionic64"
  # config.vm.box_check_update = false
  # "forwarded_port", guest: 80, host: 8080
  # "forwarded_port", guest: 80, host: 8080, host_ip: ""
  # "private_network", ip: ""
  # "public_network"
  # config.vm.synced_folder "../data", "/vagrant_data"
   config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
     vb.gui = true
  #   # Customize the amount of memory on the VM:
     vb.memory = "1024"
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2

Vagrant box

A good analogy to understand vagrant box is like GitHub repositories, considering a repository with source code which is stored inside a framework that can be controlled by Command-line interface in our case the framework corresponds to os on which the box is base on the framework corresponds to os on which the box is base on the repositories can be referred as the configuration state vagrant box as the same os can have multiple development environment setups by the provider of the vagrant box, and the command line interface refers to the vagrant command for configuration, organizing and creating new plugins.

Setting vagrant work envirnoment on your system:

It has a bare minimum installation process as just 3 line code will sequencing the Instaling vagrant, Adding of the vagrantfile, and Adding a base box

  1. Install Vagrant on your system: It is available for all Operating systems. Go and check out their official website.
  • For windows and mac, it is generally click-next installation process from the installer provided by the Vagrant official website.
  • For Linux, it covers Debian, centos, and Arch Linux based distribution as mentioned on the website.

2. Vagrant file: The next thing you need is a vagrant file as this file is the base configuration for the vagrant box we have a choose a base box or vagrant box this can be done by a couple of ways as follows

  • Using terminal create a directly name it as a vagrant, now move into the vagrant directly and use this command “vagrant init [vagrant box name]”
  • Manually creating the vagrant file similar to the above process creates a directly/folder, open the folder and create a text file add the following line of code

Use the following code to create your manual Vagrantfile just use the correct vagrant box name.

Vagrant.configure("2") do |config| = "[vagrant  box name]"

Now the Vagrantfile is being placed in your desires folder Note: this folder will serve as the shared folder between the host machine and the virtual machine.

3. Adding Vagrant box: The next step includes downloading a vagrant box this can be done in two ways

  • Navigate to the folder where the vagrantfile is being placed in the terminal and use the command “ vagrant up”. This checks the existing vagrantfile and vagrant box as we only have vagrantfile it will start downloading the vagrant box itself and once it installed completely it will run the virtual machine according to the vagrantfile configurations.
  • Or in place of “vagrant up” command use “ vagrant box add [vagrant box name]” in the above process and then run the virtual machine using “vagrant up”

Choose your Reaction!
Leave a Comment