Create your Virtual Instance with Vagrant by Hashicorp

Vagrant enables users to create and configure lightweight, reproducible, and portable development environments. Vagrant is an open-source software product for building and maintaining portable virtual software development environments; e.g., for Virtual Box, KVM, Hyper-V, Docker containers, VMware, and AWS. It tries to simplify the software configuration management of virtualization in order to increase development productivity.



Before you learn vagrant you need to know some of the following below

  • Basic linux command
  • Virtualbox (virtual machine concept)


1. Install virtualbox

$ sudo apt update
$ sudo apt install virtualbox

2. Install Vagrant

$ sudo apt install vagrant
$ vagrant -v

Create new instance

$ mkdir vagrant-server
$ cd vagrant-server

2. Init your os instance

Syntax : $vagrant init [os name]

Ex: $ vagrant init ubuntu/bionic64

#List of Os images name
Link :

3. Edit Vagrantfile

After you init directory to vagrant directory it will create a Vagrantfile which store the configuration.

$ nano Vagrantfile

You will see the config below

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

# All Vagrant configuration is done below. The “2” in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don’t change it unless you know what
# you’re doing.
Vagrant.configure(“2”) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at

# Every Vagrant development environment requires a box. You can search for
# boxes at = “ubuntu/bionic64”

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing “localhost:8080” will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# “forwarded_port”, guest: 80, host: 8080

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via to disable public access
# “forwarded_port”, guest: 80, host: 8080, host_ip: “”

# Create a private network, which allows host-only access to the machine
# using a specific IP. “private_network”, ip: “”

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# “public_network”

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder “../data”, “/vagrant_data”

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
# 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”
# end
# View the documentation for the provider you are using for more
# information on available options.

# Enable provisioning with a shell script. Additional provisioners such as
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision “shell”, inline: <<-SHELL
# apt-get update
# apt-get install -y apache2

Un-comment this line and update your instance ip address

# “private_network”, ip: “”

4. Up your instance running

$ vagrant up

It will shows like this

5. Ssh to your instance

It will create a default user vagrant for you to ssh to you instance so, you can use this command below to enter your instance

$ vagrant ssh

Finally, you can use this instance as192.168.2.6

6. Increase size of your instance

In case you want to do you just install this plug in vagrant plugin install vagrant-disksize and edit in Vagrantfile to

Vagrant.configure(‘2’) do |config| = ‘ubuntu/bionic64’
config.disksize.size = ‘50GB’


Stop your instance

You can stop your instance by this command

$ vagrant halt

Reload your instance

If you update any configuration in Vagrantfile you just run the command below to reload configuration

$ vagrant reload

Destroy your instance

When you destroy your instance mean that you want build a new instance using the same configuration in Vagrantfile, anything in your instance will be destroy with new empty instance, everything will lose. If you want to destroy your instance you just execute the command below :

$ vagrant destroy

It shown you like this when you execute this command

➜ laravel-server vagrant destroy
default: Are you sure you want to destroy the ‘default’ VM? [y/N] y
==> default: Forcing shutdown of VM…
==> default: Destroying VM and associated drives…

If you want a more comprehensive view of Vagrant and all its available commands and features, please refer to the official Vagrant documentation.

Cheer !!! Thank you …. :)

I hope this post will be a part of your knowledge.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


DevOps engineer at Z1 Flexible Solution Cambodia — Be your own unique :)