How to Set Up a Virtualized Development Environment on Debian 12 Bookworm

This article provides a step-by-step guide on how to set up a virtualized development environment on Debian 12 Bookworm.

Creating a virtualized development environment is a practical and efficient way to test applications, simulate production-like environments, and maintain clean workspaces. Debian 12 Bookworm, with its stability and robust package ecosystem, is an excellent foundation for such a setup. This guide walks through the process of setting up a virtualized development environment using tools like KVM (Kernel-based Virtual Machine), QEMU, and virt-manager.

Why Virtualization?

Before diving into the setup, let’s understand why virtualization is beneficial for development:

  • Isolation: Each virtual machine (VM) runs in its own environment, reducing conflicts between projects.
  • Replication: Easily clone and replicate environments to match production settings.
  • Flexibility: Run multiple operating systems or versions without affecting your host.
  • Testing: Safely test system updates, applications, or scripts in a sandboxed environment.

Prerequisites

Ensure your system meets the basic requirements for virtualization:

  • A 64-bit CPU with hardware virtualization support (Intel VT-x or AMD-V).
  • At least 8 GB RAM (more is better).
  • Sufficient disk space (20 GB+ recommended for VMs).
  • A clean installation of Debian 12 Bookworm.

You can check if your CPU supports virtualization using the following command:

egrep -c '(vmx|svm)' /proc/cpuinfo

If the result is 1 or more, your CPU supports virtualization.

Check if KVM is usable

kvm-ok

If kvm-ok is not available, install the cpu-checker package:

sudo apt install cpu-checker

Step 1: Install Required Virtualization Packages

Let’s install KVM, QEMU, and other necessary tools for managing virtual machines.

sudo apt update
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager

Explanation of Packages

  • qemu-kvm: KVM support for QEMU.
  • libvirt-daemon-system: Allows system-wide libvirt usage.
  • libvirt-clients: Provides virsh and other command-line tools.
  • bridge-utils: Used to set up network bridging.
  • virtinst: CLI tools for creating virtual machines.
  • virt-manager: A GUI to manage virtual machines.

After installation, ensure your user is part of the libvirt and kvm groups:

sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER

Important: Log out and back in for the group changes to take effect.


Step 2: Start and Enable the Libvirt Service

Make sure the libvirtd service is running:

sudo systemctl enable --now libvirtd
sudo systemctl status libvirtd

If everything is working, you should see an “active (running)” status.


Step 3: Verify the Installation

To check if KVM is properly installed and accessible:

virsh list --all

If this command returns without error, your setup is working.


Libvirt typically creates a default NAT-based network for virtual machines. If you want your VMs to have access to the internet and be reachable from the host, the default should suffice. However, you can create custom networks or bridges as needed.

To list existing networks:

virsh net-list --all

To start the default network (if not running):

virsh net-start default
virsh net-autostart default

Step 5: Download ISO Images for Guest OSes

You’ll need ISO files for the operating systems you want to install in your virtual machines. For development, some common choices include:

  • Debian (other versions)
  • Ubuntu Server
  • Fedora Workstation
  • CentOS Stream
  • Arch Linux
  • Windows (if needed for cross-platform testing)

Download these to your ~/Downloads or any directory of your choice.


Step 6: Create Your First Virtual Machine

There are two ways to create VMs: using the GUI (virt-manager) or via the command line with virt-install.

Option A: Using virt-manager (GUI)

  1. Open virt-manager:

    virt-manager
    
  2. Click on “Create a new virtual machine”.

  3. Choose “Local install media (ISO image)”.

  4. Browse to select your ISO file.

  5. Set RAM and CPU allocation (e.g., 2048 MB RAM and 2 CPUs).

  6. Create a virtual disk (20 GB is usually enough for testing).

  7. Follow the steps and finalize.

  8. Click Finish to boot and begin OS installation.

Option B: Using virt-install (CLI)

Example for setting up an Ubuntu 22.04 guest:

sudo virt-install \
  --name ubuntu-dev \
  --ram 2048 \
  --vcpus=2 \
  --disk path=/var/lib/libvirt/images/ubuntu-dev.qcow2,size=20 \
  --os-type linux \
  --os-variant ubuntu22.04 \
  --network network=default \
  --graphics spice \
  --cdrom=/home/youruser/Downloads/ubuntu-22.04.iso

Step 7: Access and Manage Virtual Machines

Via virt-manager

Launch the GUI and double-click on any VM to open its console. You can pause, resume, shut down, or clone VMs easily from the interface.

Via virsh (CLI)

To list running VMs:

virsh list

To start, shutdown, or destroy a VM:

virsh start <vm-name>
virsh shutdown <vm-name>
virsh destroy <vm-name>

To delete a VM (but keep disk):

virsh undefine <vm-name>

Step 8: Optimize VM Performance

To improve performance of development environments:

Use Virtio Drivers

Ensure your VMs use VirtIO for disk and network interfaces. These are paravirtualized drivers for better performance.

Enable CPU and Memory Ballooning

When using virt-manager, check the option to allow dynamic memory allocation. This can help the host manage resources better.

Use QCOW2 for Disk Images

QCOW2 supports snapshots and dynamic sizing, which is great for development.


Step 9: Snapshot and Clone VMs

Snapshot a VM

virsh snapshot-create-as --domain ubuntu-dev --name snapshot1 --description "Before update"

List snapshots

virsh snapshot-list ubuntu-dev

Revert to a snapshot

virsh snapshot-revert ubuntu-dev --snapshotname snapshot1

Clone a VM

virt-clone --original ubuntu-dev --name ubuntu-dev-clone --file /var/lib/libvirt/images/ubuntu-dev-clone.qcow2

Step 10: Use Shared Folders (Optional)

For file sharing between host and guest:

Option 1: Via VirtIO and 9p (for Linux guests)

  1. Add a shared folder to your VM using virt-manager.

  2. Inside the guest, mount the folder:

sudo mount -t 9p -o trans=virtio,version=9p2000.L hostshare /mnt

Option 2: Use NFS or Samba

You can set up a simple Samba or NFS server on your host and mount it inside the guest. This method works across platforms and guest OSes.


Conclusion

Setting up a virtualized development environment on Debian 12 Bookworm is both efficient and flexible. With KVM and tools like virt-manager, developers can quickly spin up isolated environments for various purposes — from application testing to infrastructure simulations. This setup not only minimizes system clutter but also provides the scalability and control often needed in modern development workflows.

By leveraging snapshots, shared folders, and network bridging, you can build a robust, portable, and production-like environment tailored to your needs.

Whether you’re a hobbyist developer, a DevOps engineer, or an IT student, virtualized environments on Debian Bookworm provide a dependable and scalable foundation to sharpen your tools and test your ideas.