I started using virtual machines (VMs) on my development PC about six years ago; I was keen to learn Linux, having been a Windows developer since the mid-1990s. At first, I used an old Windows PC and installed a Linux distro on it; but I quickly found out that the distro took up a lot of space, and I needed a KVM switch to manage two different PCs. It was all a bit “fiddly,” which is why I began exploring the potential of VMs.
Discovering VirtualBox was a godsend, and made things a lot more convenient. Despite all the flak Oracle gets over its databases, MySQL, and Java, Virtual Box remains an excellent and free open-source package.
After a couple of years, I discovered the joys of Hyper-V. It comes as part of Windows Pro; you just need to enable it in Windows features, and meanwhile you can’t run VirtualBox because Hyper-V uses VT-x, the Intel virtualization technology on x86 and x64 CPUs. Hyper-V is a native hypervisor that can create virtual machines on X86-64, and is generally a bit faster at launching than VirtualBox.
There’s also VMware Workstation, which is meant for commercial use and can run VMs. All three (VirtualBox, Hyper-V and VMWare) provide broadly similar capabilities: You can set up a VM and install Windows, Linux or even a Hackintosh. The VM typically uses a couple dozen GBs of disk space, along with a few GBs of RAM.
Note the terms “Host PC” and “Guest OS.” While “Host PC” means the computer you are running Hyper-V (or its equivalent) on, “Guest OS” is the OS installed in a particular VM.
So why would you use a VM for development? Here are a few reasons I’ve found over the years.
Build a Library of Different Operating Systems
If you’re writing cross-platform software, or you want to test an app on, say, Windows 7, Windows 10, Linux, and maybe on 32-bit as well as 64-bit (whatever you desire, in other words), this is where VMs are really handy. You can create a number of test environments, each with a unique VM. It’s like having a bank of PCs, configured for the different operating systems: Just boot up a test environment, install your software and run tests (all you need is lots of disk space to store all the different VMs).
You can back up VMs, so you might have a copy of a particular OS for each version of your software. I generally reckon about 30GB of disk storage is needed for one VM.
Run a Web Server or Other Software
No need for a separate networked web server when you can set up a LAMP system in a VM. You can use something such as Ubuntu Server or the full desktop version. But keep in mind how you communicate between Host and Guest: I prefer to use SSH and WinSCP to copy files. Other utilities such as FileZilla and even Dreamweaver can also use SSH.
The alternative is using Samba and setting up shared folders. If you prefer to use Subversion to Git for version control, then you can set up a Subversion server on the Guest OS.
Keep Development Software in a VM
For about twelve years, I maintained a Delphi application I had written in 2002. During that time, I changed my development PC four times. Each time I had to dig out my Delphi install media, install Delphi and the source code for the Delphi components, and recompile and reinstall a dozen components before I could build the software.
It took two to three hours each time and was a bit of a hassle, so I moved everything into a Windows VM and installed once. Now I do any bug fixing and recompiles in that VM. It’s the lazy but hassle-free approach!
Keeping older development software in a VM also avoids problems when you upgrade the host OS and need new versions.
Rather than fiddle with the version on the Pi, I installed Diet Pi in a VM and use that for development and testing. It’s no good for performance testing, since the VM runs a bit faster than my Raspberry-PI B+, but for general testing, it is easier and faster. With Diet Pi, there are five versions to download for PC (two native and one each for VMware, VirtualBox and Hyper-V), which is pretty grand!
Without a VM, installing software on a Raspberry-Pi means putting it on a SD card, which takes several minutes to burn.
Learn another OS and/or Programming Language
Occasionally I write about Python, and having a clean Ubuntu desktop in a VM means I can make a copy of the VM, run it, and then install any modules I need for testing without worrying about having to clean up afterwards. VMs make it trivial to install other programming languages and try them out without worrying about cluttering up your main PC.
With Windows and Hackintoshes running in VMs, keep potential licensing issues in mind. I doubt if Apple approves of Hackintoshes; with Windows, I’ve bought a second Windows 10 Pro licence for the VM and authenticated it. This page lists all the various OS versions that you can run in Hyper-V on Windows 10.
Note that, as Windows Subsystem for Linux (WSL) becomes more popular, you can do some of the Linux stuff I’ve mentioned using it (and it takes up only a GB of RAM, way less than VirtualBox or Hyper-V).
But WSL restricts you to having just one OS; of course, it’s Linux-only, and limited to the distros in the Windows Store (There are currently 12, are all free except for the last four in the list). WSL won’t replace Hyper-V, but it can prove handy for some uses.
Microsoft suggests that you can run VMs under Hyper-V with as little as 4 GB RAM, though I’d recommend 8GB (or better still, 16 GB). I have 64 GB RAM on my PC, and the most RAM I’ve ever had in use at once was 29 GB. In other words, no matter what your setup, chances are good that you’ll be able to experiment with VMs.