I would first try a softer way.
-
Stop the automatic updater.
sudo dpkg-reconfigure -plow unattended-upgrades
At the first prompt, choose not to download and install updates.
Make a reboot. -
Make sure any packages in an unclean state are installed correctly.
sudo dpkg --configure -a
-
Get your system up-top-date.
sudo apt update && sudo apt -f install && sudo apt full-upgrade
-
Turn the automatic updater back on, now that the blockage is cleared.
sudo dpkg-reconfigure -plow unattended-upgrades
Select the package unattended-upgrades again.
Do not jump to deleting lock files as soon as you see this issue. There might be some process actually updating packages. It might be worth waiting for a few mins.
For me it gave below error:
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?
I had logged in to my Ubuntu System after a long time and some internal process was updating something. It got resolved on it’s own (took like 5 mins).
You can check this with commands like
- sudo ps -eaf | grep -i apt
- sudo lsof /var/lib/dpkg/lock-frontend
If you see a process like “apt.systemd.daily” running you can wait for some time.
If not you can kill those processes and resume what you wanted.
- sudo kill -9 PID
Replace PID with PIDs you get from the above command. Then you can run
sudo dpkg --configure -a
to let dpkg fix itself. Either case, delete lock files only as last resort.
I simply copy-pasted a solution from another question on Ask Ubuntu, “Unable to lock the administration directory (/var/lib/dpkg/) is another process using it”. All the credit goes to zurdo.
This should be used as last resort. If you use this carelessly you can end up with a broken system. Please try the other answers before doing this.
You can delete the lock file with the following command:
sudo rm /var/lib/apt/lists/lock
You may also need to delete the lock file in the cache directory
sudo rm /var/cache/apt/archives/lock sudo rm /var/lib/dpkg/lock
After this you should be able to do your updates!