Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
FIX :
I got the above error on my Ubuntu server while trying to remove a package. In the error, you can see it is asking ‘are you root?’.
Error shows that the user that is running the command doesn’t have permission to make any changes on the server. The user need superuser privilege to execute the command on the Ubuntu server.
You tried to run a command on Debian / Ubuntu server without superuser privilege.
E: Could not open lock file /var/lib/dpkg/lock – open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
To fix the error you must either switch as ‘root’ user or run the command with sudo.
Example :
Try “sudo apt-get remove apache2” to remove the package. (Add sudo in front)
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
apache2
Check whether the user exists in sudoers file, if you’re still getting the same error. grep the username in /etc/sudoers file
You wont see any errors if you switch to root user and run the command.