KVM turns the Linux kernel into a hypervisor, and with QEMU and libvirt you get a complete virtualization stack for free. This guide shows how to install KVM on Ubuntu Server 22.04 or 24.04 so you can run your own virtual machines on a dedicated server or home lab.
Before you start
- A physical server or dedicated machine running Ubuntu Server 22.04 or 24.04 with sudo access. A normal VPS usually cannot run KVM unless the provider enables nested virtualization.
- Intel VT-x or AMD-V enabled in the BIOS/UEFI.
- Console or IPMI access in case network changes cut SSH.
Check CPU virtualization support
egrep -c '(vmx|svm)' /proc/cpuinfoA number above 0 means the CPU supports it. Install the checker for a clearer answer:
sudo apt update && sudo apt install -y cpu-checker && kvm-okYou want to see KVM acceleration can be used. If not, enable virtualization in the firmware.
Install KVM on Ubuntu
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients virtinst bridge-utilsqemu-kvm: the emulator using KVM acceleration.libvirt-daemon-system: the libvirtd management service.virtinst: providesvirt-installfor creating VMs.
Enable and check the service:
sudo systemctl enable --now libvirtdsudo virsh list --allAdd your user to the libvirt groups
sudo usermod -aG libvirt,kvm $USERLog out and back in so the groups apply. You can then run virsh without sudo.
Create a network bridge for VMs
libvirt's default NAT network (virbr0) lets VMs reach the internet but not be reached from outside. For public IPs, bridge the main interface. Edit your Netplan file, for example /etc/netplan/01-netcfg.yaml:
network:
version: 2
ethernets:
eno1:
dhcp4: false
bridges:
br0:
interfaces: [eno1]
addresses: [203.0.113.10/24]
routes:
- to: default
via: 203.0.113.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]Replace the interface name and addresses with yours, then apply from the console with sudo netplan try, which rolls back automatically if you lose connection. See static IP with Netplan for more Netplan detail.
Verify the installation
lsmod | grep kvmshowskvm_intelorkvm_amd.virsh net-list --allshows thedefaultnetwork.ip a show br0shows the bridge with your IP.
Optional: install virt-manager on your desktop and connect over SSH (File → Add Connection) for a graphical view.
Troubleshooting
- kvm-ok says acceleration cannot be used: enable VT-x/AMD-V (sometimes called SVM or Intel Virtualization Technology) in firmware and fully power-cycle.
- Permission denied on /var/run/libvirt/libvirt-sock: your session lacks the
libvirtgroup; log in again. - Lost SSH after netplan apply: use the console to fix the YAML; always test with
netplan try.
Frequently asked questions
Can I install KVM on a VPS?
Only if the provider exposes the vmx/svm CPU flag through nested virtualization. Most do not by default.
Do I need a desktop environment?
No. Manage VMs with virsh and virt-install, or remotely with virt-manager or Cockpit.
Is KVM free?
Yes. KVM, QEMU and libvirt are open source and included in Ubuntu's repositories.
