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.
3. How To Fix dpkg: error: dpkg frontend lock is locked by another process.
3.1 Question1.
- When I install google chrome with the command sudo dpkg -i ./google-chrome-stable_current_amd64.deb in Ubuntu, it throws the error dpkg: error: dpkg frontend lock is locked by another process.
- Can you tell me how to fix it?
3.2 Answer1.
- First, you can run the command lsof /var/lib/dpkg/lock-frontend to return the process id which is locking the file.
- Then you can run the command sudo kill -9 PID to kill the process that locks the /var/lib/dpkg/lock-frontend file.
- Then you can run the command sudo rm /var/lib/dpkg/lock-frontend to remove the lock file.
- Now you can run the command sudo dpkg -i ./google-chrome-stable_current_amd64.deb to install the google chrome again.
so when i run this command to download wine stable (sudo apt install –install-recommends winehq-stable) it says “waiting for cache lock: could not get lock /var/lib/dpkg/lock-frontend .”