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.



It's possible, but it's NOT RECOMMENDED for most general purpose users.

Edit /etc/apt/apt.conf.d/50unattended-upgrades to enable this option:

// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGTERM. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "false";

Obviously, you must have a clear understanding of how to use SIGTERM.

Note that the same file has a setting to move Unattended Upgrades to shutdown (like Windows).

Alternately, you can edit /etc/apt/apt.conf.d/20auto-upgrades to disable automated updates and upgrades, and then program your own method. We recommend against disabling merely to upgrade manually...folks tend to slack on that method after a few weeks.

Alternately, automated updates and upgrades use systemd timers. You can change the time at which they run by simply editing /lib/systemd/system/apt-daily.timer and /lib/systemd/system/apt-daily-upgrade.timer. Remove the randomization and specify the constant time you wish.

For General Purpose Users: You probably don't need any of these tools, but they are available. In general, DO NOT INTERRUPT APT under most circumstances. Doing so inexpertly WON'T release the lock, and may damage your system. Cleaning up after an apt breakage can be confusing and tedious...and is completely avoidable. For most users (including experts), best practice is to simply wait until apt completes it's task. Good time for a sandwich.

  • It happens most of times with machines and virtual machines where there's a lot of days between one boot and the other. Maybe lot of things changed, certificates revoked, remote server changes, practically If i kill the service and cast an apt-get update manually everything works ok but unattended upgrades just do mess. In my experience unattended upgrades works fine just if you regularly run the machines day by day.. if there's too much time in days between one boot and another it get stuck ;\ – user3450548 Nov 6 '19 at 0:52
  • Use case should be part of the Question. – user535733 Nov 6 '19 at 1:43
  • added usecase in the question as requested – user3450548 Nov 9 '19 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.