0

I have a fresh installation of Ubuntu 18.04-x64.

In the terminal I enter the command:

sudo apt update

And I get the following error:

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

When I run sudo apt update again, the command runs successfully and I get:

Reading package lists... Done                                                  
Building dependency tree       
Reading state information... Done
103 packages can be upgraded. Run 'apt list --upgradable' to see them.

This behaviour is consistent. I have a VM snapshot of the fresh Ubuntu installation and everytime the first sudo apt update fails with this error and the second sudo apt update completes successfully.

EDIT: Should have mentioned that the sudo apt update command lies inside a script. Running the script with sudo privileges seems to have fixed the problem.

1 Answers1

0

That issue is happening because the system identifies the fact the lock file is being used by another process. You can identify the process and kill it by

$ps aux | grep -i apt
$sudo kill -9 <pid>

If something happened during an apt-get process, like a system shutdown, then there will be no process having the file locked, by the problem will still be there. In that case you can reconfigure the necessary files, as follows:

$sudo rm /var/lib/apt/lists/lock
$sudo rm /var/cache/apt/archives/lock
$sudo rm /var/lib/dpkg/lock
$sudo dpkg --configure -a
Sarriman
  • 316