Background
So I logged into my Ubuntu machine after a long time and I decided to update my installed software to the latest versions. But I see following screen and the update is stuck: “waiting for unattended-upgr to exit”
In this post, I will show you how to fix this issue.
Fixing “waiting for unattended-upgr to exit” issue
To begin, make sure all packages are in a clean state and correctly installed For this you can run:
- sudo dpkg --configure -a
However, this fails for me with the following error
In fact, "sudo apt-get upgrade" also fails for me:
athakur:~$ sudo apt-get upgrade E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
This could be due to multiple causes. Most probably some other internal update is running and using the lock. You can check this with the following commands:
Note: If you see a process like "apt.systemd.daily" using the lock, please wait for a few mins. This is auto-scheduler that updates your system. If you do not want this behavior you can go to "Software and Updates" and disable auto-updates:
Anyways, if you do not wish to wait you can always kill the process. Above commands - ps and lsof should give you PIDs corresponding to the process using the locks. You can kill them by running
If above does not work as well you can always delete the lock file (Not recommended)
and resume any update you might have. Please note we should not do this under ideal conditions. Lock files are meant to be present for special purposes. That being said, sometimes Softwares do go into an inconsistent state, and lock files have to be removed manually.
Once you kill the process or remove the lock file manually run following command to let dpkg fix itself:
- ps -eaf | grep -i apt
- lsof /var/lib/dpkg/lock-frontend
Note: If you see a process like "apt.systemd.daily" using the lock, please wait for a few mins. This is auto-scheduler that updates your system. If you do not want this behavior you can go to "Software and Updates" and disable auto-updates:
Anyways, if you do not wish to wait you can always kill the process. Above commands - ps and lsof should give you PIDs corresponding to the process using the locks. You can kill them by running
- sudo kill -9 PID
Replace PID with actual PID (Process ID) you see in the output of the above commands. Once done you can resume the software updates. You can also do
- sudo apt-get upgrade
to upgrade your software.
If above does not work as well you can always delete the lock file (Not recommended)
- sudo rm -rf /var/lib/dpkg/lock-frontend
and resume any update you might have. Please note we should not do this under ideal conditions. Lock files are meant to be present for special purposes. That being said, sometimes Softwares do go into an inconsistent state, and lock files have to be removed manually.
Once you kill the process or remove the lock file manually run following command to let dpkg fix itself:
- sudo dpkg --configure -a
This is the same command we ran as the very 1ts step.