KVM (Kernel-based Virtual Machine) is an open-source virtualization technology built into the Linux kernel. It lets you run multiple isolated virtual machines on a single host, each with its own operating system, CPU resources, memory, storage, and network interface.
KVM supports both Linux and Windows VMs, making it useful for dev work, testing, and server consolidation.
This guide covers how to install KVM on Ubuntu 18.04, set up networking, and create your first VM. The same steps apply to Ubuntu 16.04 and other Ubuntu-based distributions like Linux Mint and Elementary OS.
<strong>Prerequisite:</strong> You need a 64-bit host to run guests with more than 2 GB of RAM and to support both 32-bit and 64-bit VMs.
Your CPU must support hardware virtualization to use KVM. Intel processors need VT-x (vmx) support, and AMD processors need AMD-V (svm) support.
Run this command to check:
bashgrep -Eoc '(vmx|svm)' /proc/cpuinfo
A number above zero means virtualization is supported. Zero means it is not.
Virtualization may also be disabled in your BIOS. Use the kvm-ok tool from the cpu-checker package to check:
bashsudo apt updatesudo apt install cpu-checker
bashkvm-ok
If KVM is ready to use, you will see:
INFO: /dev/kvm existsKVM acceleration can be used
If you get an error, virtualization is either disabled or unsupported. Enable it in your BIOS settings and refer to your motherboard documentation for the exact steps.
Run this command to install KVM and the required supporting packages:
bashsudo apt install qemu-kvm libvirt-bin bridge-utils virtinst virt-manager
Here is what each package provides:
After the install, the libvirt daemon starts automatically. Confirm it is running:
bashsudo systemctl is-active libvirtd
Output: active
To create and manage VMs without running everything as root, add your user to the libvirt and kvm groups:
bashsudo usermod -aG libvirt $USERsudo usermod -aG kvm $USER
Log out and log back in to apply the group membership changes. $USER automatically holds your current username.
KVM creates a virtual bridge called virbr0 during installation. It uses NAT to give guest VMs internet access through the host machine.
List the current bridges with:
bashbrctl show
You will see virbr0 alongside virbr0-nic. The virbr0-nic device is virtual and exists only to keep the virbr0 bridge MAC address stable across reboots. No physical interface is attached to it by default.
The NAT setup works well for most desktop users. To make guest VMs reachable from outside your local network, you will need to create a custom bridge connected directly to the host’s physical network interface.
With KVM installed, use Virtual Machine Manager to create your first VM.
Download the ISO for the OS you want to install, open the Activities menu, type “Virtual Machine Manager”, and launch the app.
Follow these steps:
The VM boots into the OS installer. Follow the on-screen steps to complete the installation. Once done, access the VM through virt-manager, over SSH, or via the serial console.
KVM is now installed and running on your Ubuntu machine. You can create as many Linux or Windows virtual machines as your hardware supports. Got questions? Leave a comment below.