Skip to content
FR
  1. LuzineDebug
  2. Systems (Windows, macOS, Linux)
  3. E: Could not get lock /var/lib/dpkg/lock-fronten…
Systems (Windows, macOS, Linux) Beginner ≈ 10 min to fix

Fix "E: Could not get lock /var/lib/dpkg/lock-frontend" (apt, Ubuntu, Debian)

Error message
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1234 (unattended-upgr)
  • E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
  • E: Could not get lock /var/lib/dpkg/lock. It is held by process 5678 (apt-get)
  • E: Could not get lock /var/lib/apt/lists/lock. It is held by process 910 (apt)
  • E: Unable to lock directory /var/lib/apt/lists/
  • E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
In short

Another program is already using apt or dpkg, most often automatic updates (unattended-upgrades) right after boot. Wait for it to finish or close the other package manager. Do not delete the lock files: while the process is running, that can corrupt the package database.

Be the first to confirm this fix

What this error means

apt and dpkg place a lock on files such as /var/lib/dpkg/lock-frontend so two programs never modify the package database at the same time. The kernel holds this lock as long as the process that took it is alive, and it goes away by itself when that process ends. The message gives its PID and name, truncated to 15 characters (unattended-upgr for unattended-upgrades). The lock file always exists, which is normal: deleting it releases nothing and lets a second apt work alongside the first, hence the warning "removing the lock file is not a solution".

Common causes

  1. Automatic updates: unattended-upgrades and the apt-daily timers often run a few minutes after boot, especially on a fresh cloud VM.
  2. Another package manager open: Software Updater or Ubuntu Software (packagekitd), Synaptic, or an apt started in another terminal or SSH session.
  3. Provisioning in progress: cloud-init is still installing packages on first boot while your script already runs apt install.
  4. Stuck process: an apt waiting for an answer to a prompt (debconf) in another session, or a frozen installation.

Step-by-step fix

  1. Identify the process

    See which program holds the lock and for how long. Replace 1234 with the PID from the message.

    bash
    ps -o pid,etime,cmd -p 1234
    sudo fuser -v /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock
    pgrep -a 'apt|dpkg|unattended'
  2. Wait for automatic updates to finish

    If it is unattended-upgrades or apt-daily, let it finish: it usually takes a few minutes. You can follow its progress in the logs.

    bash
    sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.log
    sudo tail -f /var/log/dpkg.log
  3. In a script: wait for the lock instead of failing

    apt can wait for the lock to be released with the DPkg::Lock::Timeout option (in seconds). On a cloud VM, also wait for cloud-init to finish before installing.

    bash
    cloud-init status --wait
    sudo apt-get -o DPkg::Lock::Timeout=600 update
    sudo apt-get -o DPkg::Lock::Timeout=600 install -y nginx
  4. Close the other package manager

    Close Software Updater, Ubuntu Software or Synaptic, and cleanly finish the apt in the other terminal (answer its prompt if it is waiting for one).

  5. Truly stuck process: stop it cleanly

    Only if the process has made no progress for a long time (nothing new in /var/log/dpkg.log), stop it with a normal signal, not kill -9 in the middle of an installation. Then repair half-configured packages.

    bash
    sudo systemctl stop unattended-upgrades
    # or, for another process
    sudo kill 1234
    
    sudo dpkg --configure -a
    sudo apt-get install -f
  6. Deleting a lock: only as a very last resort

    It is almost never needed: a reboot releases every lock. Only delete the files if fuser and pgrep confirm that no apt or dpkg process is running and the error persists. Then immediately run dpkg --configure -a.

    bash
    # Both must print nothing
    sudo fuser -v /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/lib/apt/lists/lock
    pgrep -a 'apt|dpkg'
    
    sudo rm /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock /var/lib/apt/lists/lock /var/cache/apt/archives/lock
    sudo dpkg --configure -a

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • In provisioning scripts, use cloud-init status --wait and -o DPkg::Lock::Timeout=600 rather than sleep loops.
  • Do not disable unattended-upgrades to avoid the error: you would lose automatic security fixes. Adjust the schedule of the apt-daily and apt-daily-upgrade timers instead.
  • Run only one package manager at a time on a machine.

Frequently asked questions

Can I delete /var/lib/dpkg/lock-frontend?

Not while an apt or dpkg process is running: two simultaneous installs can corrupt the package database. Wait, or stop the process cleanly. Deleting it is only justified after checking that no process holds the lock.

What is unattended-upgr?

The truncated name of unattended-upgrades, the service that automatically installs security updates on Ubuntu and Debian.

The error comes back after a reboot, why?

Automatic updates start again at boot. Wait a few minutes, then run sudo dpkg --configure -a if a previous installation had been interrupted.

Useful tools for this error

More Systems (Windows, macOS, Linux) errors

All Systems (Windows, macOS, Linux) errors →