How To Use and Install a Virtual Machine
Published: 2023-08-11 15:48:42

## Introduction

Welcome to the world of technology, where innovation knows no bounds! Picture this: effortlessly running an entirely different operating system on your computer. Sounds impossible? Well, that is the power of virtual machines, a game-changer for developers worldwide if you ask me.

Though the origins of virtual machines trace back over [six decades](https://en.wikipedia.org/wiki/Virtual_machine), their relevance in today's rapidly evolving tech landscape remains unchanged. These virtual wonders have changed how we develop, test, and deploy software, opening doors to limitless possibilities.

In this article, we are going to unveil and explore the fascinating realm of virtual machines, unlocking some of the secrets to their endless potential.

## Prerequisites

Whether you're a tech newbie or an experienced developer eager to explore new horizons, this article is tailor-made for you. It will guide you on an exciting journey through different operating systems using virtual machines. Let's unravel the mysteries of these versatile tools and unlock boundless possibilities together!

## Understanding Virtual Machines

A **virtual machine** (VM) is defined as the emulation or imitation of a computer system, equipped with the functionality of a physical or real computer. In this virtual realm, the real machine which oversees the operation is referred to as the "host" while the emulated VM is referred to as the "guest".

The uses of VMs stretch as far as one’s imagination empowering developers to imitate diverse operating systems of their choice.

**Some of the advantages of VMs include**:

- Providing a substitute for a real machine.

- Creating multiple isolated environments on a single physical system.

- There’s no compliance needed between the guest and the host machine.

There are two types of VMs namely:

1. System Virtual Machine

2. Process Virtual Machine

In this article, we delve into the realm of System VMs, which serve as temporal replacements for a real machine, providing the necessary functions required to execute an entire operating system. A hypervisor (computer software or hardware that runs VMs) is required to execute and manage one or more virtual environments.

For more insights into the types of VMs refer [here](amit_mangal_)

## System Requirements

Before diving into the world of virtual environments on your computer, your machine must meet the necessary specifications for compatibility. Also, VMs are frequently used on Windows, Mac, Solaris, and Linux operating systems. Here are the basic requirements:

- A 64-bit i686 Processor: This is very essential to ensure a smooth and efficient performance.

- 1.3gHz*2 Processor Speed: This is highly recommended to handle the resource-intensive operations of running virtual machines.

- At least a 4GB Hard disk space: Sufficient storage space is essential to accommodate the virtual machine files and operating system images.

- At least 4GB RAM or more: This ensures optimal performance of running multiple environments. For more demanding tasks, consider upgrading to a higher RAM capacity.

## Choosing a Virtualization Software

Managing VMs requires certain tools, there are several software programs available for programmers which can be used to manage virtual environments. However, for our learning journey and ensuring a seamless experience with amazing tools, we will focus on two important tools, namely:

Oracle VM: This software enables you to imitate and run a different operating system on a host machine. For instance, even if your machine has a Windows operating system, Oracle VM allows you to effortlessly run a Linux operating system as a guest.

Vagrant: This is a tool that helps you control your virtual machine. It provides a simple and intuitive way to manage your virtual environments. Just as a car needs a driver, Vagrant allows you to bring your virtual machine to life, and perform various operations with ease.

## Why Choose Oracle VM and Vagrant?

Oracle VM and Vagrant are ideal choices, especially for absolute beginners. Their user-friendly interfaces and straightforward installation process make them accessible to everyone. Additionally, these tools have gained popularity among programmers worldwide for their reliability and versatility in handling virtual environments. To learn more about other virtual machine software, [refer here](https://www.spiceworks.com/tech/devops/articles/what-is-virtual-machine/#:~:text=Every%20virtual%20machine%20has%20its,OS%2C%20Linux%2C%20and%20Solaris).

## Installing Oracle VM and Vagrant: Your First Virtual Environments

Both Oracle VM and Vagrant offer users the flexibility to create diverse virtual environments supporting multiple operating systems. In this guide, we will walk through the installation process of Oracle VM and Vagrant enabling you to set up a Linux operating system like Ubuntu.

To ensure secure and reliable downloads of the software, you can follow the links provided below:

Download OracleVM [here](https://www.virtualbox.org/wiki/Downloads)

After clicking the above link, you should be redirected to the Oracle VM website's download page. Choose the link that matches your operating system (Windows, MacOS, or Linux).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhwhadtami87sanloett.png)

Download Vagrant [here](https://developer.hashicorp.com/vag)

Once you click the link, you will be taken to the Vagrant website's download page. Choose the link that matches your operating system(Windows, MacOS, or Linux).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98bmffxkkqmz1l4l1sbd.png)

After the download is complete, navigate to the downloaded files and initiate the installation process for both Vagrant and Oracle VM.

Follow the on-screen instructions, just like you would when installing any other application or game on your computer.

Next, you'll need to open the Terminal on MacOS or the Command Prompt on Windows:

For MacOS Users:

Go to your Applications folder, then open the "Utilities" folder.

Look for the "Terminal" application and launch it.

For Windows Users:

Click on the Start menu and type "Command Prompt" in the search bar.

Select the "Command Prompt" app from the search results to open it.

Once you have the Terminal (MacOS) or Command Prompt (Windows) open, you're ready to proceed with setting up your virtual environments using Vagrant and Oracle VM.

**Set Up Your Virtual Environments**

Regardless of your operating system, you'll need to enter the following commands into your terminal or command prompt. This step will guide you through the process of creating your virtual environments using Vagrant and Oracle VM. Before proceeding, ensure you have a working internet connection, as it is crucial for the setup process.

Please note that after entering the commands, you should see the images displayed below in your terminal (MacOS) or command prompt (Windows). These images will serve as confirmation that you have successfully created your virtual environments.

```
vagrant box add ubuntu/focal64
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ktn71v8m8omcrgq4smwg.png)

After executing the above command, note that it may take a while to download depending on your network connection, so exercise some patience with your computer system.

The command "vagrant box add ubuntu/focal64" allows you to add the Ubuntu image from the internet, Vagrant will download the specified virtual machine image and store it locally on your computer.

In this case, "ubuntu/focal64" refers to the official Ubuntu 20.04 LTS (Focal Fossa) virtual machine image that is hosted on the Vagrant cloud. The "focal64" part indicates that it is a 64-bit version of Ubuntu 20.04.

The next step is to create a vagrant file that will hold the "ubuntu/focal64" virtual machine using the command:

```
vagrant init ubuntu/focal64
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/487nauc1oqwlw25uysz6.png)

The above command should display something similar to the image below:

Please make sure to run the command "vagrant init ubuntu/focal64" in the directory of your choice. These commands are only needed once to create a working VM. On subsequent uses of your virtual environment, you only need to start your machine and change into it using the command below:

```
vagrant up
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/at3gs30fk3auacv0ea5m.png)

The command "vagrant up" starts your VM and you should see something similar to the image below. Please note that the startup may take a while, and you should see the message "Machine Booted and Ready!" like in the image below. If you don't see the expected message, you may need to start your machine all over again using "vagrant reload".

To change into your machine, use the command below:

```
vagrant ssh
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxv9d6v9qxtmy0sho4g5.png)

After the execution of the above command, your Command Prompt (Windows) or Terminal (MacOS) should display something similar to the image below:

Congratulations! You've successfully created a working VM and you are now ready to explore the Linux operating system. This opens up a world of possibilities for your projects, allowing you to use your preferred applications and software in your Linux environment. For instance, if you need to program using the "emacs" text editor you can run the command to install:

```
apt install emacs
```
This command "apt install emacs" allows you to install the "emacs" text editor on your Linux operating system.

For more Vagrant commands, you can use the command below it lists all the commands associated with it:

```
vagrant --help
```
Once you've completed your projects and you wish to shut down the virtual environment, you can use the "exit" command and then use "vagrant halt" to close all operations.

Now that you're all set, go ahead and unleash your creativity in this Linux environment!

## Some Common Troubleshooting Issues During Installation

Here are some tips for some common issues:

A message saying ["unable to initialize vagrant at an early stage"](https://docs.oracle.com/cd/E64076_01/E81582/html/vmrns-bugs-3.4.3-25686610.htm): If you encounter this issue, it is likely due to an outdated version of PowerShell. To resolve it, update your PowerShell to the latest version. You can find the latest version and installation instructions on the official [PowerShell website](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3).

A message that says "Time up, failed to connect with box In the specified time frame": If you face this error, you may need to increase the allocated time for booting your virtual machine. You can do this by adjusting the timeout settings in your Vagrant file. For detailed instructions on modifying the timeout settings, refer to the [Vagrant documentation](https://developer.hashicorp.com/vagrant/docs) or the official Vagrant [community forums](https://www.vagrantup.com/community).

## Conclusion

VMs have been in existence for a long time and they are still relevant in the constantly evolving world of technology, Whether you are a Full stack developer, frontend, or back-end developer, it is a tool to include in your toolbox.

Numerous possibilities for using VMs continue to amaze me. Start exploring the world of virtual machines today and unlock a new realm of possibilities, grasp the opportunity to make your projects easier, and expand your knowledge of varieties of operating systems.