> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix "Could not get lock /var/lib/dpkg/lock"

> Fix "Could not get lock /var/lib/dpkg/lock-frontend": find the apt or unattended-upgrades process holding it, let it finish, then run dpkg --configure -a.

"Could not get lock /var/lib/dpkg/lock-frontend" means another program is installing or updating packages on Ubuntu or Debian right now, and only one may do so at a time. Usually it is the automatic security updates (`unattended-upgr`) that run shortly after boot. Wait for it to finish, or check what holds the lock with `ps aux | grep -E 'apt|dpkg'`. Never delete the lock files.

```text theme={null}
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?
```

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 2 to 15 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13 | Root or sudo access |

## Before you start

* This error is about APT and dpkg, the package tools of Ubuntu and Debian. AlmaLinux and Rocky use `dnf`, which waits for its own lock by itself.
* A **lock** is a marker a program sets so no second program changes the package database at the same time. Two installs at once can corrupt it.
* Commands use `sudo`. As root, leave it out.

> [!WARNING]
>
> Don't run `rm /var/lib/dpkg/lock*` or `rm /var/lib/apt/lists/lock`. Deleting a lock while another install is running can leave half-installed packages and a broken package database. dpkg itself warns that removing the lock file is always wrong.

## Cause 1: Automatic updates are running

Ubuntu and Debian install security updates in the background with `unattended-upgrades`. It runs on a daily timer that also catches up on missed runs at boot, so it is often busy soon after the server starts. The message then names `unattended-upgr` (the process name is cut to 15 characters) or `apt.systemd.daily`.

**Check:**

```bash theme={null}
ps aux | grep -E '[a]pt|[d]pkg|[u]nattended'
```

**Fix:** wait. It usually finishes within a few minutes; a large batch of updates can take longer. To have your command wait instead of failing, use `apt` (which waits up to two minutes by default) or give `apt-get` a timeout in seconds:

```bash theme={null}
sudo apt-get -o DPkg::Lock::Timeout=600 install nginx
```

## Cause 2: You are running apt somewhere else

A second SSH session, a [tmux or screen](https://help.freakhosting.com/portals/other/how-to-keep-ssh-sessions-running-with-tmux-and-screen.md) window, a control panel or a script may be installing something.

**Check** which process holds the lock:

```bash theme={null}
sudo lsof /var/lib/dpkg/lock-frontend
```

```text theme={null}
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
apt-get 1234 root    4uW  REG  252,1        0 393333 /var/lib/dpkg/lock-frontend
```

**Fix:** go back to that session and let the command finish, or answer its question if it is waiting for input.

## Cause 3: An install was interrupted

If a lost SSH connection or a reboot stopped an install halfway, the lock is gone but dpkg reports:

```text theme={null}
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.
```

**Fix:** finish the interrupted work, then repair dependencies:

```bash theme={null}
sudo dpkg --configure -a
sudo apt install -f
```

## Cause 4: An apt process is stuck

Only if a process has used no CPU for a long time (for example 30 minutes or more) and isn't waiting for input should you stop it.

**Check** with `ps` (Cause 1). If the process is waiting on the network, a broken mirror may be the reason: see [apt and dnf repository errors](https://help.freakhosting.com/portals/other/how-to-fix-apt-and-dnf-repository-errors.md).

**Fix:** stop it gently first, then repair:

```bash theme={null}
sudo kill 1234
sudo dpkg --configure -a
```

Use the PID from your own output. Only use `sudo kill -9 1234` if the normal `kill` has no effect after a minute.

## How to check it worked

```bash theme={null}
sudo apt update
```

It should run without any `Could not get lock` line and end with `Reading package lists... Done` or a summary of upgradable packages.

## Frequently asked questions

### Why does this happen every time I log in to a new server?

On first boot the server checks for and installs security updates. Wait five to ten minutes after creating or rebuilding a server before you install software.

### Should I turn off unattended upgrades to avoid this?

No. They install security fixes. If you need control over timing, adjust them instead: see [enable automatic security updates](https://help.freakhosting.com/portals/other/how-to-enable-automatic-security-updates.md).

### What is the difference between lock and lock-frontend?

`lock-frontend` is held by the tool you run (`apt`, `apt-get`); `lock` is held by dpkg while it unpacks packages. `/var/lib/apt/lists/lock` is used by `apt update`. The fix is the same for all of them.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Update Linux packages](https://help.freakhosting.com/portals/other/how-to-update-linux-packages.md)
>
> apt and dnf updates done right.

> [card] [Automatic security updates](https://help.freakhosting.com/portals/other/how-to-enable-automatic-security-updates.md)
>
> Configure unattended-upgrades.

> [card] [apt and dnf repository errors](https://help.freakhosting.com/portals/other/how-to-fix-apt-and-dnf-repository-errors.md)
>
> Release file, key and mirror errors.

> [card] [Kill a process](https://help.freakhosting.com/portals/other/how-to-kill-a-process-on-linux.md)
>
> Stop a stuck program safely.

***

> [!NOTE]
>
> **Checked against the [Debian dpkg FAQ on database locks](https://wiki.debian.org/Teams/Dpkg/FAQ#db-lock) and the official [Ubuntu package management guide](https://ubuntu.com/server/docs/how-to/software/package-management/)** on 4 November 2026; the lock error, dpkg's warning, `apt` waiting for the lock and `-o DPkg::Lock::Timeout` were reproduced on a copy of the package database on Ubuntu 24.04 LTS (apt 2.8.3, dpkg 1.22.6).

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.