Getting Started with Vagrant

What is Vagrant?

Vagrant is an open-source tool that simplifies the setup and management of virtual development environments. It allows developers to create and configure reproducible, lightweight, and portable virtual machines (VMs) or containers for different projects. With Vagrant, you can easily create and share development environments across teams, ensuring consistent setups and reducing time spent on environment configuration.

Top 10 Vagrant Commands

  1. vagrant init: Initializes a new Vagrant environment in the current directory. It creates an initial Vagrantfile with a basic configuration.
  2. vagrant up: Creates and starts the virtual machine defined in the Vagrantfile. If the virtual machine doesn't exist, it will be created.
  3. vagrant halt: Stops the running virtual machine. It gracefully shuts down the guest operating system.
  4. vagrant reload: Restarts the virtual machine. It applies any changes made to the Vagrantfile or provisioning scripts.
  5. vagrant destroy: Stops and deletes the virtual machine. This command removes all traces of the virtual machine from your system.
  6. vagrant suspend: Suspends the virtual machine. It saves the current state of the guest operating system to disk and stops the virtual machine.
  7. vagrant resume: Resumes a suspended virtual machine. It restores the virtual machine from the saved state.
  8. vagrant ssh: Logs into the virtual machine via SSH. It establishes an SSH connection to the guest operating system.
  9. vagrant status: Shows the status of the virtual machine. It displays whether the machine is running, halted, suspended, or not created.
  10. vagrant provision: Runs the configured provisioning scripts on the virtual machine. It applies any changes to the guest operating system.

How can we Install CentOs on Vagrant?

Step 1. Navigate to Vagrant Cloud in the Google.

Step 2. Search for the required Os; in the example, I will be using CentOs.

You will find various boxes from the list of CentOs available in Vagrant.

Step 3. Select the box as per your Use Case. I will be using Generic CentOs in this example.

CentOS on Vagrant

Step 4. Initialize the box using the command vagrant init {command as per your os}

Generic/centos9s

For Generic CentOs 9 — vagrant init generic/centos9s 

Once you have initialized, follow the next step

Step 5. Bringing your VM up using Vagrant up

Step 6. Once your VM is up. Login to your VM using vagrant ssh.


Similar Articles