๐ A Beginner's Guide to Crafting Your First Virtual Machine with Vagrant - Day 11/90
In the world of software development and IT infrastructure management, the use of virtual machines has become increasingly popular. These virtual machines, which simulate the hardware and software configurations of physical computers, are essential tools for testing, development, and even production environments. One powerful tool that simplifies the process of creating and managing virtual machines is Vagrant. In this comprehensive guide, I will walk you through the process of creating your first virtual machine using Vagrant.
If you are unaware of Vagrant please check out the below article first to get better insights of Vagrant.
Before we pick our box from the vagrant cloud let us see what this term is.
Introduction to Vagrant Cloud
Vagrant Cloud is an online service provided by HashiCorp, the creators of Vagrant. It acts as a repository for pre-configured virtual machine images known as "boxes." These boxes save you time by providing pre-built environments with various operating systems and software configurations.
Browsing Boxes
To find the right box for your needs, visit the Vagrant Cloud website. Here, you can search for boxes that match your requirements. When you find a suitable box, make a note of its name, as you'll need it in the next step.
Creating Your First Virtual Machine
Selecting a Box
For this guide, let's choose an Ubuntu box, a widely used Linux distribution in the development and server environments. I have copied the selected text now let's bring the vm to life.
Initializing Your Virtual Machine
Now that you've selected a box name, it's time to initialize your virtual machine. Use the following command, replacing 'ubuntu/jammy64' with the name of your chosen box:
vagrant init ubuntu/jammy64
This command creates a new Vagrantfile with the necessary configuration settings.
Launching Your Virtual Machine
To start your virtual machine, execute this command:
vagrant up
This command downloads the selected box from Vagrant Cloud (if it's not already cached on your machine) and starts the virtual machine.
Accessing Your Virtual Machine
Congratulations, your virtual machine is now up and running! To access it, use the following command:
vagrant ssh
This command establishes a secure shell connection to your virtual machine, granting you direct access to its terminal.
To check the status of virtual machine run this command.
# Displays status of specific machine
vagrant status
# Displays status of all machines
vagrant global-status
Stoping Your Virtual Machine
To stop your machine use below command.
vagrant halt
Terminating Your Virtual Machine
To destroy your vm run
vagrant destroy
Conclusion
I hope this guide has made setting up your first virtual machine using Vagrant a breeze. As you become more familiar with Vagrant, you'll appreciate its benefits in simplifying and streamlining your development and testing processes. Happy coding, and may your virtual machines serve you well! ๐๐ฉโ๐ป๐