How to fix KVM permission denied error on Ubuntu 18.04

/dev/kvm device: permission denied is the error that I got while trying to run Android Virtual Device(AVD) on a fresh install of Ubuntu 18.04.

Error

The error message also shows a hint on what could be wrong: Grant current user access to /dev/kvm. A quick google search reveals that this is a common problem.

The easiest way to fix this would be to install qemu-kvm and then give appropriate permission to the current user.

Install qemu-kvm.

$ sudo apt install qemu-kvm

Use the adduser command to add your user to the kvm group.

$ sudo adduser <username> kvm

And then own the file /dev/kvm using chown.

$ sudo chown <username> /dev/kvm

Fix error

After the above steps the AVD should work as expected.

Android emulator boots