Simple Guide to Creating Virtual Machines

ยท

4 min read

Simple Guide to Creating Virtual Machines

Why VM's?

We've all seen the famous meme: "It works on my machine!" Often, we face issues arising from our work environment, leading us to spend countless hours debugging code in search of a solution that doesn't exist. Docker and containerization have emerged to address these problems, but what about setting up a local work environment? That's where Virtual Machines (VMs) come into play. Let's delve into what VMs are and how to set one up in just a few simple steps.

It Works On My Machine Meme

What are VMs?

When I was a child, I had a toy box in which I stored all my toys, whether it was a shiny Hot Wheels car or a well-worn metal Beyblade from my epic imaginary battles. There were days when I spent countless hours searching for a specific toy. But what if this toy box could be a magical one that sorted similar toys into separate smaller boxes?

Now that I've grown up, my toys have changed, and my laptop has become my favorite playground. However, the habit of embarking on adventures with different toys hasn't changed; it's just that the toys have been replaced with tools and packages.

Virtual machines are akin to the magical toy box, assisting me in sorting and organizing various tools and packages while keeping me from getting lost as I attempt to create something new.

Let's Get Started!

So here we will go through two methods of creating VMs on your local setup.

Using Oracle VirtualBox and OSBoxes

  • Download the setup file for your machine and install VirtualBox from the VirtualBox Download page

  • Download an OS image for the virtual machine you want to create. Extract the contents of the zip file, which should contain a VDI file, to be used in later steps - CentOS Image for VirtualBox.

  • Launch the Oracle VM VirtualBox app from the startup menu.

  • Click the "New" button on the application interface to start creating a new VM.

  • Enter details like Name, Folder location, Type (according to the OS image you downloaded), and Version. Click "Next" to proceed.

  • Allocate hardware resources to the virtual machine by adjusting the slider to set base memory and CPUs. Click "Next" - it's recommended to allocate at least 2GB memory and 2 CPUs for smooth running.

  • Select "Use an existing Virtual Hard Disk File" and browse to the location where you extracted the image file from OSBoxes. Click "Next".

  • On the final screen, confirm the virtual machine configuration and click "Finish". Your new VM should appear in the VirtualBox application window.

  • To start your virtual machine, click the "Start" button, and your VM is up and running.

Note: All OSBoxes images have the below username and password.

Username: osboxes
Password: osboxes.org
Root Account Password: osboxes.org

Using Vagrant and Oracle VirtualBox

Vagrant is a command-line utility tool for managing virtual machines and their entire lifecycles in a single workflow.

  • Download and install Vagrant from the Vagrant Setup page.

  • Download the Oracle VirtualBox setup from the VirtualBox Download page and install it on your machine.

  • Launch a terminal and navigate to the location where you want to initialize Vagrant virtual machines.

    Use the following commands:

    1. cd "your-folder-location" to navigate to the folder.

    2. vagrant to check the Vagrant installation and display common command options.

  • Initialize a virtual machine using the command vagrant init "virtual-box-name". Find the list of virtual box names and commands on the Vagrant Cloud boxes page - CentOS.

  • Run the command vagrant up. This downloads the necessary files, creates the virtual machine, and configures its basic settings.

Once the vagrant up command finishes, your virtual machine is ready and booted up! You can customize the VagrantFile to configure and change the default settings of the virtual machine.

Conclusion

In conclusion, virtual machines provide an efficient way to create isolated environments for your development projects. By using tools like Oracle VirtualBox and Vagrant, you can easily set up and manage VMs, ensuring a smooth and consistent workflow across different platforms. Embrace the power of VMs and enhance your development experience by creating customized local work environments.

Enjoy creating your local dev environments with different virtual machines ๐Ÿง‘โ€๐Ÿ’ป

ย