2

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?

N0rbert
  • 103,263

2 Answers2

3

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.

cocomac
  • 3,824
N0rbert
  • 103,263
0

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.

Nmath
  • 12,664