When I try to run my Android app on an emulator I get this error:
/dev/kvm permission denied.
I checked the permissions and ad
Under Ubuntu, the permissions of /dev/kvm
usually look like this:
$ ls -l /dev/kvm
crw-rw---- 1 root kvm 10, 232 May 24 09:54 /dev/kvm
The user that runs the Android emulator (i.e. your user) needs to get access to this device.
Thus, there are basically 2 ways how to get access:
Check if your user is already part of the kvm group, e.g.:
$ id
uid=1000(juser) gid=1000(juser) groups=1000(juser),10(wheel)
If it isn't then add it with e.g.:
$ sudo usermod --append --groups kvm juser
After that change you have to logout and login again to make the group change effective (check again with id
).
Alternatively, you can just can widen the permissions of the /dev/kvm
device.
Example:
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
FWIW, this is the default on other distributions such as Fedora and CentOS.
Check the effectiveness of the above commands with another ls
. You should see output similar to:
$ ls -l /dev/kvm
crw-rw-rw-. 1 root kvm 10, 232 2020-05-16 09:19 /dev/kvm
Big advantage: You don't need to logout and login again for this change to be effective.
chmod
and chown
directly on /dev/kvm
- 1) these changes aren't persistent over reboots and 2) since /dev/kvm
permissions are controlled by the udev daemon, it can 'fix' its permissions at any time, e.g. after each emulator run/dev/kvm
- your emulator just requires read and write permissions/dev/kvm
- I don't know what's up with that - looks like cargo cult/dev/kvm
devicesudo setfacl -m u:$USER:rwx /dev/kvm
Worked for me.
Just one slight improvement on Jerrin's answer on fixing this error with Ubuntu 18.04 by utilizing $USER
variable available in the bash terminal. So you could use the following commands two commands:
sudo apt install qemu-kvm
Add the current user to the kvm group
sudo adduser $USER kvm
Also if you are still having issues, one other problem for me was the way in which I installed Ubuntu. I made the mistake of checking the box during installation for installing 3rd party software which did not play nice with my nvidia graphics card for development. So I reinstalled Ubuntu with this third party software unchecked.
Then after installation, open up Software & Updates and go to the Additional Drivers tab. Select the most up to date proprietary drivers that have also been tested and apply changes. Should restart the machine for the changes to take affect.