Score:2

APT Update not responding as expected

us flag

I have tried to resolve the following issue in Ubuntu, but so far have only been able to resolve the issue by rebooting my Linux box.

I was running the sudo apt update command and soon realized that I had no internet for some reason. So I pressed the Ctrl + Z keys to stop the process. When I was sure the internet was back online, I attempted to restart the sudo apt update command and encountered the following error:

root@myubuntu-OS:/home/root# apt update
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/

Other than restarting the system, is there a way to clean up my mess and run this process again?

cocomac avatar
cn flag
Does this answer your question? [Could not get lock /var/lib/apt/lists/lock](https://askubuntu.com/questions/335794/could-not-get-lock-var-lib-apt-lists-lock)
Score:3
zw flag

Ctrl + Z does not stop a process (Ctrl + C does that). Instead, it moves it to the background. You have to execute fg command in the same terminal to move sudo apt update back to the foreground. This is why when you tried sudo apt update a second time it failed - the process in the background already locked apt (only one process should be using apt at once, so it locks it to prevent multiple processes from interfering with each other).

If you have closed this terminal then remove lock-files by

sudo rm -v /var/lib/dpkg/lock* /var/cache/apt/archives/lock

and then run

sudo apt update

again.

johnsageek avatar
us flag
Excellent feedback! Thank you I received some feedback telling me to run lsof /var/lib/dpkg/lock which did the job. But your answer, gave me the information to understand what was going on and thus understand much more then copying and pasting a command string. Give a man a fish and he will eat for a day. Teach a man how to fish and he will eat forever. Thanks again for your excellent answer
Score:0
ng flag

It's locked because another process is using it. This was a result of killing the task while it was operating, leaving the lock in place.

The easiest solution is to reboot, or you can remove lock files using this answer.

If this continues to happen even when you did not kill the update task, it's probably because your system is behind on updates and your GUI software center or unattended-upgrades has placed the lock to download the list of available software and make critical security fixes.

You can prevent this by routinely running sudo apt update followed by sudo apt upgrade to keep your system up-to-date.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.