Vagrant simple and basic

Tram Ho

Hello everyone. In this article, I will guide you through the basics of using Vagrant.

I. What is Vagrant?

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and a focus on automation, Vagrant reduces development environment setup time, increases equivalent output, and makes “work on my machine” a relic of the past.

You can understand that Vagrant creates a configuration file and deploys a virtual machine with just a few simple command lines instead of opening applications like VMWare, Virtualbox, HyperV, … performing a series of creation operations. a virtual machine. Vagrant also makes changing the parameters of the virtual machine much simpler than manually configuring it.

Vagrant plays a support role for applications: VMWare, Virtualbox, HyperV, … so to use, you will need to install those applications first.

II. Install Vagrant

2.1. Install on Windows

On a Windows environment I will use Virtualbox and Git to run with Vagrant. When running virtual machines with Vagrant, the virtual machines will run in the background, so you don’t need to open Virtualbox, but the virtual machine can still work normally.

Step 1: Go to Vagrant homepage and select the version for Windows to install.
Step 2: Create a directory for the virtual machine
Step 3: Go to and select the image you want to install.
Step 4: Go to the created directory and run the command vagrant init generic/ubuntu2004 to create the file Vargantfile
Step 5: Change the configuration in the Vargantfile
Step 6: Run the virtual machine
vagrant up

The options network, provider, provision can be left by default without configuration.

2.2. Install on Ubuntu

On Ubuntu environment do the installation using the command
sudo apt-get install vagrant
vagrant version

II. Commonly used basic commands

vagrant [options] <command> [<args>]

Run virtual machine

vagrant up

Shutdown virtual machine

vagrant halt

Flying color virtual machine

vagrant destroy

Restart the virtual machine and update the configuration according to the new Vagrantfile

vagrant reload

Suspend the virtual machine

vagrant suspend

Resume suspended virtual machine

vagrant resume

Check virtual machine status in current folder

vagrant status

SSH into the virtual machine

vagrant ssh

Check all running virtual machines

vagrant global-status

Manage snapshots

Make a snapshot
vagrant snapshot save level1

Check out snapshots
vagrant snapshot list

Delete the snapshot
vagrant snapshot delete level1

Load snapshot
vagrant snapshot restore level1

Check vagrant version

vagrant version

Show all support commands

vagrant --help

Thank you all for reading my post and when you’re done, please give me your feedback. The following article is better thanks to your feedback. If you find this post useful, give me an upvote. I thank you.


Share the news now

Source : Viblo