How To Fix The Error waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 13083 (unattended-upgr)

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.

  1. 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.
  2. This issue happened when the program just updating Ubuntu to install new software.
  3. 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.
  4. And the warning message has said, the process’s (that lock this file) id is 12827 and the process name contains unattended-upgr.
  5. 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.

  1. 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.
  2. Because Ubuntu has enabled some background processes to update the system automatically to install software updates & security packages.
  3. 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.
  4. 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.
  5. Now you can run your program successfully.

3. How To Fix dpkg: error: dpkg frontend lock is locked by another process.

3.1 Question1.

  1. 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.
  2. Can you tell me how to fix it?

3.2 Answer1.

  1. First, you can run the command lsof /var/lib/dpkg/lock-frontend to return the process id which is locking the file.
  2. Then you can run the command sudo kill -9 PID to kill the process that locks the /var/lib/dpkg/lock-frontend file.
  3. Then you can run the command sudo rm /var/lib/dpkg/lock-frontend to remove the lock file.
  4. Now you can run the command sudo dpkg -i ./google-chrome-stable_current_amd64.deb to install the google chrome again.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Clicky