Learn Vagrant from Scratch : Initial Setup and Boxes

Setup and Boxes

Vagrant reads its setting and instructions from Vagrantfile. It is generally present in its home directory. This file is created once you start initialize the vagrant.

Supposing you are in your root directory of vagrant. Run this to initialize your vagrant.

vagrant init

Now you will have a Vagrantfile in your root directory. Open the file in editor to start making changes for your virtual machinevagrant1

sudo vi Vagrantfile

or you can use any editor of your choice.

Now that you have Vagrantfile initilized, now we have to add a box to vagrant. Once the box is added it can be reused.

You can view different types of boxes present on list of boxes on hashicorp.

For adding the box run this command

vagrant box add hashicorp/precise64

hashicorp/precise64 is the name of box you want to run in virtual machine. hashicorp/precise64 is standard ubuntu 12.04.

Now that you have added the box you want your Vagrantfile to use this box. Edit your Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"

change the config.vm.box to the box you want to run. you can also define box version by using

config.vm.box_version = "1.1.0"

It will take some time and then you will have your virtual machine running.

Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.