Recently, I run the command $ sudo apt update in my Ubuntu virtual machine, it runs successfully. But after that, when I run the command $ sudo apt upgrade, it show me the warning message Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 12827 (unattended-upgr). This article will tell you why it happens and how to fix it.
1. Why The Error Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend happen.
- From the error message, we can see that there is another program ( process ) that is locking the /var/lib/dpkg/lock-frontend file, dpkg means Debian package manager.
- This issue happened when the program just updating Ubuntu to install new software.
- The goal of this locking mechanism is to avoid the Ubuntu system data is changed by two or more programs at the same time which can cause inconsistent errors.
- And the warning message has said, the process’s (that lock this file) id is 12827 and the process name contains unattended-upgr.
- So we can run the command ps -ef | grep unattended-upgr to display the locking process’s detail information.
$ ps -ef | grep unattended-upgr root 653 1 0 08:10 ? 00:00:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal jerry 77529 77475 0 09:09 pts/1 00:00:00 grep --color=auto unattended-upgr
2. How To Fix The Error.
- If the locking process name contains tex like apt.systemd.daily update, what you need to do is just wait for the programm to exit.
- Because Ubuntu has enabled some background processes to update the system automatically to install software updates & security packages.
- You can click the Show Applications icon on Ubuntu bottom left corner, then search the keyword Software & Update to open the Software & Update window, then click the Updates tab to see them.
- If the locking process is not the system updater process, then you can run the command sudo kill <process_id> or sudo kill -9 <process_id> to kill the locking process and then run the command sudo rm <locking_file> to remove the locking files.
- Now you can run your program successfully.