← Back to list

Setting Up Virtual Machines the Smart Way: A Beginner’s Guide to Vagrant

After understanding what virtual machines are, the next step in my DevOps journey was actually creating and managing them.

Hasini Madhushani · 2026-04-23 17:05 · 0 claps · 2.2 min read
#vagrant #vagrantfile #ubuntu #centos #vm-management
Open on Medium ↗
Wiki topics: BIZ · Business Strategy ☁️ · DevOps & Cloud 🔓 · Open Source

Setting Up Virtual Machines the Smart Way: A Beginner’s Guide to Vagrant

After understanding what virtual machines are, the next step in my DevOps journey was actually creating and managing them.

At first, I used VirtualBox to manually create VMs. It worked, but it quickly became repetitive and time-consuming.

That’s when I discovered Vagrant.

This tool completely changed how I work with virtual machines.

Why Not Just Use VirtualBox Manually?

When I created VMs manually using VirtualBox, I had to:

  • Download ISO files
  • Configure CPU, RAM, storage
  • Install the OS step by step
  • Set up networking manually

Doing this once is fine. Doing this multiple times becomes frustrating.

Also, it’s easy to make mistakes.

This is where automation becomes important.

What is Vagrant?

Vagrant is a tool that allows you to create and manage virtual machines using simple commands.

Instead of manually configuring everything, you define your VM in a file, and Vagrant does the rest.

In simple terms: Vagrant automates virtual machine setup.

It works with hypervisors like:

  • VirtualBox
  • VMware

Setting Up Virtual Machines Using Vagrant (Step-by-Step)

Now let’s get into the practical part.

Step 1: Create a Project Directory

mkdir /e/vagrant-vms
cd /e/vagrant-vms

Create separate folders for each VM:

mkdir centos
mkdir ubuntu

Step 2: Create a CentOS Virtual Machine

Navigate to the CentOS folder:

cd centos

Initialize Vagrant:

vagrant init eurolinux-vagrant/centos-stream-9 --box-version 9.0.48

This creates a Vagrantfile (configuration file).

Step 3: Start the VM

vagrant up

This will:

  • Download the box (if not already downloaded)
  • Create the virtual machine
  • Start it automatically

Step 4: Check VM Status

vagrant status

To see all VMs:

vagrant global-status

Step 5: Connect to the VM

vagrant ssh

Check current user:

whoami

Switch to root user:

sudo -i

Step 6: Stop or Restart the VM

Stop the VM:

vagrant halt

Restart the VM:

vagrant reload

If you modify the Vagrantfile, you need to run vagrant reload to apply changes.

Step 7: Delete the VM

vagrant destroy

This removes the VM completely.

Useful Vagrant Commands (Quick Reference)

  • vagrant up → Create & start VM
  • vagrant halt → Stop VM
  • vagrant reload → Restart VM
  • vagrant destroy → Delete VM
  • vagrant ssh → Connect to VM
  • vagrant status → Check VM status
  • vagrant global-status → Show all VMs
  • vagrant box list → Show downloaded boxes
  • history → Show command history

Step 8: Create an Ubuntu Virtual Machine

Navigate to Ubuntu folder:

cd ../ubuntu

Initialize Ubuntu VM:

vagrant init ubuntu/jammy64 --box-version 20241002.0.0

Then repeat:

vagrant up

Why Vagrant is Powerful

After using Vagrant, I realized:

  • No manual OS installation
  • Same environment can be recreated anytime
  • Faster setup
  • Less human error

This is exactly what DevOps is about:

Consistency + Automation

Key Takeaways

  • Vagrant automates VM creation and management
  • It works with tools like VirtualBox (hypervisor)
  • You can spin up environments in minutes
  • Commands are simple and repeatable
  • It reduces manual effort and mistakes

Final Thoughts

Setting up virtual machines manually helped me understand the basics. But using Vagrant showed me how powerful automation can be.

This is where DevOps really begins.

If you’re also learning DevOps, try this yourself. You’ll understand much more by doing than just reading.


메타데이터
post_id
6c711581925b
slug
setting-up-virtual-machines-the-smart-way-a-beginners-guide-to-vagrant-6c711581925b
url
https://medium.com/@hasinipm17/setting-up-virtual-machines-the-smart-way-a-beginners-guide-to-vagrant-6c711581925b
canonical_url
https://medium.com/@hasinipm17/setting-up-virtual-machines-the-smart-way-a-beginners-guide-to-vagrant-6c711581925b
author_url
https://medium.com/@hasinipm17
status
ok
fetched_at
2026-07-11 01:37:02