---
title: "How to Install KVM on Ubuntu Linux"
description: "Learn how to use Ubuntu and Install KVM for kernel-based virtualization as an alternative to solutions such as VMware!"
canonical: "https://adamtheautomator.com/ubuntu-install-kvm/"
---

# How to Install KVM on Ubuntu Linux

> Learn how to use Ubuntu and Install KVM for kernel-based virtualization as an alternative to solutions such as VMware!

Source: https://adamtheautomator.com/ubuntu-install-kvm/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Install KVM on Ubuntu Linux](https://adamtheautomator.com/wp-content/uploads/2022/07/How-to-Install-KVM-on-Ubuntu-Linux.jpg)

# How to Install KVM on Ubuntu Linux

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)3 August 20227 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Ubuntu Linux](/tag/ubuntu-linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Checking Your Hardware](#checking-your-hardware)
*   [Using the lscpu Command](#using-the-lscpu-command)
*   [Using the cpu-checker Tool](#using-the-cpu-checker-tool)
*   [Installing KVM on Ubuntu](#installing-kvm-on-ubuntu)
*   [Creating Your First Virtual Machine in KVM](#creating-your-first-virtual-machine-in-kvm)
*   [Using the virt-manager (GUI)](#using-the-virt-manager-gui)
*   [Using the virt-install (CLI)](#using-the-virt-install-cli)
*   [Managing VMs in the Command Line](#managing-vms-in-the-command-line)
*   [Listing VMs](#listing-vms)
*   [Shutting Down VMs](#shutting-down-vms)
*   [Starting a VM](#starting-a-vm)
*   [Deleting a VM](#deleting-a-vm)
*   [Conclusion](#conclusion)

You manage virtual machines (VMs) on your network as a system administrator. There are many ways to create and manage VMs, and KVM is a popular solution for Ubuntu Linux.

This guide will teach you how to configure and install KVM on Ubuntu Linux. You will also learn the basic commands for managing VMs with KVM. By the end of this guide, you’ll know how to create and manage VMs using KVM on your Ubuntu server.

Ready? Read on to get started!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have an [Ubuntu](https://adamtheautomator.com/install-ubuntu/) server with the following specifications.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

*   A minimum of 4 GB of RAM and 2 virtual CPUs (vCPUs). The more CPU and RAM, the better.
*   An ISO image for the operating system you want to install on your VM. This guide will be using a [Fedora Workstation](https://getfedora.org/en/workstation/download/) ISO file, but feel free to have any Linux operating systems ISO.

If you do not have a server that meets these specifications, you can follow along with a free trial from a cloud provider like AWS, Google Cloud, or Azure.

Related:[Get Microsoft Azure Free: Your Goto Guide](https://adamtheautomator.com/azure-free/)

## Checking Your Hardware

Before you begin, you must check if your CPU supports virtualization. KVM requires CPU virtualization extensions, such as Intel VT-x or AMD-V.

This tutorial assumes that you’ve already logged in to the Ubuntu host via an SSH client or the desktop environment (if available) and have a terminal window open.

Related:[How to Set up the SSH Chrome Extension](https://adamtheautomator.com/ssh-chrome-extension/)

> _Note: This entire tutorial will be running the terminal commands logged in as the root user. If you don’t log in as root, you may prepend sudo for each command as needed._

### Using the `lscpu` Command

The lscpu command is a built-in command that displays the CPU architecture information. To check if your CPU supports virtualization, run the below command to determine whether your machine supports virtualization.

```powershell
lscpu | grep Virtualization:
```

If your host computer supports virtualization, you’ll get a result similar to the screenshot below. A blank result means that there’s no virtualization capability.

![Checking virtualization support with lscpu](https://adamtheautomator.com/wp-content/uploads/2022/07/image-421.png)

Checking virtualization support with lscpu

### Using the `cpu-checker` Tool

If you need further confirmation about the hardware virtualization support status, another way to check is with the cpu-checker package. This package contains tools for evaluating the CPU support for various features, including virtualization.

1\. Update your package repositories by running the below command.

```bash
apt update -y
```

2\. Execute the below command to install the cpu-checker package.

```bash
apt install -y cpu-checker
```

Related:[Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

3\. Finally, check if your CPU supports virtualization by running this command.

```bash
kvm-ok
```

If you get the following result, your CPU supports virtualization with KVM.

![Checking CPU virtualization support - OK](https://adamtheautomator.com/wp-content/uploads/2022/07/image-422.png)

Checking CPU virtualization support – OK

If your CPU is not capable of virtualization, you’ll get the following result instead. In this case, your current hardware is sufficient, and you cannot install KVM.

![Checking CPU virtualization support - NOT OK](https://adamtheautomator.com/wp-content/uploads/2022/07/image-423.png)

Checking CPU virtualization support – NOT OK

## Installing KVM on Ubuntu

Now that you have verified that your CPU supports virtualization, you are ready to install KVM on your Ubuntu server. This guide uses Ubuntu 20.04, but the steps should be similar for other versions of Ubuntu.

1.  To install KVM on Ubuntu, run the below `apt` command. The list below breaks down the packages you’re installing.

*   `qemu-kvm` – This package provides accelerated KVM support. This package is a [userspace](https://en.wiktionary.org/wiki/userspace#English) component for [QEMU](https://www.qemu.org/docs/master/about/index.html), which is responsible for accelerating KVM guests.
*   `libvirt-daemon-system` – This package provides the `libvirt` daemon and management tools. The `libvirt` daemon is responsible for creating, managing, and destroying virtual machines on your server.
*   `libvirt-clients` – This package provides the `libvirt` command-line interface for managing virtual machines.
*   `bridge-utils` – This package provides the [userland](https://en.wiktionary.org/wiki/userland) utilities for configuring virtual network bridges. On a hosted virtualization solution like KVM, a network bridge connects the guest VM network to the host network.
*   `virt-manager` – This package provides a graphical user interface (GUI) for managing virtual machines.

```bash
apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils -y
```

2\. If your Ubuntu host has a desktop environment, install the virt-manager package, which provides a graphical user interface (GUI) for managing virtual machines.

```powershell
apt install virt-manager -y
```

3\. To enable the libvirt daemon to start automatically at boot, run the below command.

```bash
systemctl enable libvirtd
```

4\. To check the status of the libvirt daemon, run the below command:

```bash
systemctl status libvirtd
```

The service status should be enabled and active (running).

![Checking the libvirtd daemon status](https://adamtheautomator.com/wp-content/uploads/2022/07/image-424.png)

Checking the libvirtd daemon status

If libvirtd is not running, run the below command to start the daemon.

```powershell
systemctl start libvirtd
```

Related:[Correct Way of Using Ubuntu systemctl to Control Systemd](https://adamtheautomator.com/ubuntu-systemctl/)

5\. Finally, run the below command to check if KVM is loaded in the kernel. The output of this command will show the kvm modules loaded in the kernel. At this point, you’ve successfully installed KVM.

```bash
lsmod | grep -i kvm
```

![Checking if KVM is loaded in the kernel](https://adamtheautomator.com/wp-content/uploads/2022/07/image-425.png)

Checking if KVM is loaded in the kernel

## Creating Your First Virtual Machine in KVM

You’re ready to create your first virtual machine now that you’ve installed KVM. In this section, you will learn how to create a VM using the Virtual Machine Manager (GUI) and the command line.

### Using the `virt-manager` (GUI)

Follow the below steps to create a VM using the Virtual Machine Manager. This section applies only if your Ubuntu host has a desktop environment. If not, skip this section.

1\. Run the below command to launch the Virtual Machine Manager.

```bash
virt-manager
```

![Launching the Virtual Machine Manager](https://adamtheautomator.com/wp-content/uploads/2022/07/image-426.png)

Launching the Virtual Machine Manager

2\. To create a new VM, click the computer icon on the top left.

![Clicking the new virtual machine button](https://adamtheautomator.com/wp-content/uploads/2022/07/image-427.png)

Clicking the new virtual machine button

3\. On the New VM window, select Local install media(ISO image or CDROM) and click on Forward.

![Selecting the operating system installation method](https://adamtheautomator.com/wp-content/uploads/2022/07/image-428.png)

Selecting the operating system installation method

4\. Click Browse —> Browse Local to choose the ISO image of the operating system you want to install. This example will set the ISO file at _/root/Fedora-Workstation-Live-x86\_64-36-1.5.iso_.

![Choosing the ISO installation file](https://adamtheautomator.com/wp-content/uploads/2022/07/image-429.png)

Choosing the ISO installation file

5\. Click on Forward after choosing the ISO.

![Click Forward after choosing the ISO file](https://adamtheautomator.com/wp-content/uploads/2022/07/image-430.png)

Click Forward after choosing the ISO file

6\. In the next window, adjust your VM’s CPU count and memory allocation. Ensure that the values you choose are sufficient. This example leaves the default values unchanged. Click Forward to proceed.

![Choosing the CPU and Memory settings](https://adamtheautomator.com/wp-content/uploads/2022/07/image-431.png)

Choosing the CPU and Memory settings

7\. Next, set the disk image size for this VM. Increase or decrease the disk size as needed. For this demonstration, the disk size of 10 GB is acceptable for the VM. Click Forward to move to the next step.

![Allocating the disk space for your VM](https://adamtheautomator.com/wp-content/uploads/2022/07/image-432.png)

Allocating the disk space for your VM

> _The default location for storing VM disk images is /var/lib/libvirt/images._

8\. Next, type in the VM name or leave the default. In this example, the VM name will be _fedora01_. Leave everything else unchanged and click on Finish to create the VM.

![Setting the VM name](https://adamtheautomator.com/wp-content/uploads/2022/07/image-433.png)

Setting the VM name

9\. Once KVM has created the VM, the VM console will show up, and you can now [install the operating system as usual](https://www.linuxtechi.com/how-to-install-fedora-workstation/).

![Virtual machine console](https://adamtheautomator.com/wp-content/uploads/2022/07/image-434.png)

Virtual machine console

10\. At this point, you now have one VM, as you can see in the Virtual Machine Manager. After finishing the operating system install, shut down the VM by clicking the power button icon.

![Shutting down the VM after installing the guest operating system](https://adamtheautomator.com/wp-content/uploads/2022/07/image-435.png)

Shutting down the VM after installing the guest operating system

### Using the `virt-install` (CLI)

If you prefer working with the command line, virt-install will be your tool when creating new VMs. Run the below command to create a VM with the following details.

> _For the complete details, refer to the [virt-install man page](https://linux.die.net/man/1/virt-install) or run virt-install –help._

*   `--name Fedora02` – Set the VM name as `Fedora02`.
*   `--vcpu 1` – Allocate 1 vCPU to the VM.
*   `--memory 1024` – Allocate 1024MB of RAM to the VM.
*   `--cdrom /root/Fedora-Workstation-Live-x86_64-36-1.5.iso` – Specifies the ISO file location containing the operating system installer.
*   `--disk size=10` – Specifies the VM disk size in GB (`10`).
*   `--graphics listen=0.0.0.0` – Configures the display server to listen on all interfaces.

```bash
virt-install --name Fedora02 --vcpu 1 --memory 1024 --cdrom /root/Fedora-Workstation-Live-x86_64-36-1.5.iso --disk size=10 --check disk_size=off
```

If you run the command from the terminal in the Ubuntu host with a desktop environment, the virt-install automatically launches the view-viewer window displaying the VM console.

![Running virt-install on Ubuntu with a desktop environment](https://adamtheautomator.com/wp-content/uploads/2022/07/image-436.png)

Running virt-install on Ubuntu with a desktop environment

If you executed the `virt-install` command from a remote SSH terminal or a host without a desktop environment, you’d get the below result.

![Running virt-install on Ubuntu without a desktop environment](https://adamtheautomator.com/wp-content/uploads/2022/07/image-437.png)

Running virt-install on Ubuntu without a desktop environment

In this case, you must access the KVM guest console from another machine capable of running graphical applications using the [virt-viewer](https://virt-manager.org/download/) client.

> _Note: You must install the virt-viewer client for your operating systems, such as Windows and Linux. Follow this_ [_link_](https://virt-manager.org/download/) _for the download and install instructions._

## Managing VMs in the Command Line

Now that you have created some VM, the hardest part is over. Next is learning how to manage your VMs from the command line. The management part may vary slightly depending on whether you are using the virt-manager GUI tool or virsh CLI.

In this section, you will learn how to perform some of the most common VM management tasks from virsh CLI.

### Listing VMs

You first need to know how to list the existing VMs on your system. To do so, run the below command.

```bash
virsh list --all
```

As you can see below, there are currently two VMs. The list also shows each VM’s state.

![Listing Existing VMs](https://adamtheautomator.com/wp-content/uploads/2022/07/image-438.png)

Listing Existing VMs

### Shutting Down VMs

The next thing you would want to do is to shut down a VM when you no longer need them running.

To gracefully shut down a VM, run the `virsh shutdown` command followed by the VM name. For example, run the below command to shut down the `Fedora02` VM.

```bash
virsh shutdown Fedora02
```

![Gracefully shut down a VM](https://adamtheautomator.com/wp-content/uploads/2022/07/image-439.png)

Gracefully shut down a VM

The guest operating system running inside the VM can be unresponsive, and you can not even restart it from the `virsh` CLI. In such cases, run the `virsh destroy` command to stop the VM forcefully.

```powershell
virsh destroy Fedora02
```

![Forcefully stop the VM](https://adamtheautomator.com/wp-content/uploads/2022/07/image-440.png)

Forcefully stop the VM

### Starting a VM

When you need to start the VM again, run the `virsh start` command followed by the VM name. The below example will start up `Fedora02`.

```bash
virsh start Fedora02
```

![You can start the VM again ](https://adamtheautomator.com/wp-content/uploads/2022/07/image-441.png)

You can start the VM again

### Deleting a VM

When you no longer need a VM, you can delete it to free up resources on your system.

1\. First, stop the VM instance. You cannot delete a VM that is running.

```powershell
virsh destroy Fedora02
```

2\. Get the VM’s associated storage. This example gets the storage list for Fedora02.

```powershell
virsh domblklist Fedora02
```

Copy the Source value of the storage to delete.

![Getting the VM storage list](https://adamtheautomator.com/wp-content/uploads/2022/07/image-442.png)

Getting the VM storage list

3\. Now, run the below command to delete the VM and its disk image. The virsh undefine deletes the VM, and the –storage option accepts the comma-separated list of storage to remove.

```bash
virsh undefine Fedora02 --storage /var/lib/libvirt/images/Fedora02-1.qcow2
```

![Deleting a VM and its storage](https://adamtheautomator.com/wp-content/uploads/2022/07/image-443.png)

Deleting a VM and its storage

## Conclusion

In this article, you learned how to install KVM on Ubuntu Linux and create and manage virtual machines using the virsh CLI tool. You also learned how to use virt-manager to create virtual machines graphically.

KVM is a powerful and free virtualization solution that can run multiple virtual machines on a single host. KVM has many advanced features that make it suitable for running production workloads.

You can [run thousands of KVM Guests on Amazon bare metal servers](https://github.com/aws-samples/aws-bare-metal-kvm-demo) to save money on your AWS bill. You can also use KVM for disaster recovery by replicating your physical servers to Amazon EC2 instances.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-install-kvm%2F&text=How%20to%20Install%20KVM%20on%20Ubuntu%20Linux)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-install-kvm%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fubuntu-install-kvm%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/ubuntu-ntp.jpg)

### [How to Setup Ubuntu NTP Server](/ubuntu-ntp/)

Learn to configure an Ubuntu NTP server for precise time synchronization across your network. Ensure seamless operations with accurate timekeeping!

![](https://adamtheautomator.com/wp-content/uploads/2022/04/How-to-Install-Apache-on-Ubuntu.jpg)

### [Install Apache on Ubuntu and Master Website Traffic Management](/install-apache-on-ubuntu/)

Ready to optimize your website for high traffic? Install Apache on Ubuntu with this step-by-step guide and ensure smooth performance under heavy loads.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
