Could not get lock /var/lib/apt/lists/lock - open - Ubuntu 18.04


#1

When trying to perform:

$ sudo apt update

I receive an error message stating that:

Reading package lists... Done
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

Restarting the Ubuntu system does not help. Any hints?


#2

Most of the time this could be caused by an automatic system update running in the background. Normally you do not need to do anything just wait.

To disable the automatic updates hence to avoid the error message edit the /etc/apt/apt.conf.d/20auto-upgrades and change it:
FROM:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

TO:

APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "1";

Another situation when this error can occur is when some other process or user is using apt tool to install, update or remove packages. In that case you can attempt to see which process is holding lock on /var/lib/dpkg/lock file by using:

$ sudo lsof /var/lib/dpkg/lock

Alternatively try:

$ ps -ax | grep -E 'apt|dpkg'

Hope this helps…

Lubos