Ubuntu – Terminate unattended-upgrades or whatever is using apt in ubuntu 18.04 or later editions

18.04aptaptitudeunattended-upgrades

It happens often that when I boot my Ubuntu 18 machines and I want to manually update my software I get stuck into errors involving something already using apt (endless waiting unattended-upgrades and / or other services).

Most of time with machines or virtual machines that are not booted frequently, where a boot and the next are followed by many days or 4-5 months, meanwhile maybe some certificates, mirrors or somethings else has changed and unattended-upgrades just get stuck on endlessy timeouts trying to contact servers that are not there anymore..

This is the error:

user@ubuntu:~$ sudo apt-get upgrade
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarly unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

I would like to know if there's a command line to gently terminate all instances using apt, leave the apt environment and configuration in a coherent state and be ready to use the gui version of ubuntu Software Updates or apt-get.

Thanks

Best Answer

The long term solution to your problem is easy:

sudo apt remove unattended-upgrades

There is, in my opinion, no excuse for the poor design of unattended-upgrades. Blocking every software install, and even system shutdown, for hours with an automatically initiated process that a user cannot shut down without risking corrupting the apt database: the mind boggles.

In the short term, you can either wait and hope, or send it a SIGKILL and hope for the best - it will be OK if it is either taking a long time to download, or is stuck because of a missing certificate, faulty connection, or one of the million other reasons unattended-upgrades can trip over its own shoelaces. You may need to manually remove the lock file.

After that, hurry up and uninstall unattended-upgrades to regain control of your computer.

Related Question