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 logout/login or restart your system.

After the above steps the AVD should work as expected.

Android emulator boots

Update: I have removed the very bad approach of running sudo chown <username> /dev/kvm. Thank you to all the people who had pointed it out in the comments :)