Skip to content

Fix APT Lock ​

Symptoms ​

An install or update task on the server fails, and the Output of the event contains one of these lines:

text
E: Could not get lock /var/lib/dpkg/lock-frontend
E: Unable to acquire the dpkg frontend lock
E: Could not get lock /var/lib/apt/lists/lock
E: Unable to lock directory /var/lib/apt/lists/

For the Unable to acquire the dpkg frontend lock error, the Solution section in the event details links to this page.

Cause ​

Ubuntu only lets one package program (apt, apt-get, dpkg) run at a time. The running program "locks" the package manager until it finishes. The error appears when:

  • The server is installing security updates in the background (common right after a new server boots).
  • A previous installation was interrupted (lost connection, server reboot…) and left the lock behind.

If the server is just updating itself, you usually only need to wait a few minutes and run the task again.

Fix it with the Fix APT Lock button ​

  1. Open the server and find the Utilities group on the overview page.
  2. Click Fix APT Lock.
  3. Read the description, then click Agree.
  4. Watch the Fix APT Lock event on the Events page. Once it succeeds, run the task that failed earlier again.

The utility will:

  1. Stop all running apt and apt-get processes.
  2. Remove the package manager lock files.
  3. Finish configuring any half-installed packages (dpkg --configure -a).
  4. Refresh the package list.

The button is disabled while the server is running another FlashPanel task; wait for that task to finish.

Warning

The utility immediately stops running apt processes, even ones that are installing or updating normally. Interrupting them can leave the package being installed broken. Only use it when you are sure no installation is running (for example, the error is still there after waiting 10–15 minutes).

Fix it manually ​

If the button does not solve the problem, connect via SSH as root and do the following:

  1. See which program holds the lock:

    bash
    sudo lsof /var/lib/dpkg/lock-frontend
    ps aux | grep -E 'apt|dpkg' | grep -v grep

    If you see unattended-upgrade or an apt command running, wait for it to finish.

  2. If the process is stuck (no change for a long time), stop it using the PID in the second column:

    bash
    sudo kill <PID>
  3. Repair half-installed packages and refresh the package list:

    bash
    sudo dpkg --configure -a
    sudo apt-get install -f
    sudo apt-get update
  4. If it still fails, reboot the server and try again. When contacting FlashPanel support, include the ID and Output of the failed event.

"dpkg was interrupted" error ​

The task fails with:

text
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.

A previous package installation or upgrade stopped halfway (lost connection, server reboot, full disk…) and left some packages half-configured. The Solution section in the event details links to this section.

  1. Make sure no installation or update is still running (step 1 of Fix it manually).

  2. Click Fix APT Lock as described above; it also finishes configuring half-installed packages. Or run these commands as root:

    bash
    sudo dpkg --configure -a
    sudo apt-get install -f
    sudo apt-get update
  3. Run the task that failed again.

If these commands fail with No space left on device, free up disk space first, see Disk Full.