Unable to Lock the Administration Directory Error

How to Fix Unable to Lock the Administration Directory Error on Ubuntu?

At the beginning of their administrative journey, GNU users are faced with various errors and problems that cannot always be resolved from the first try. Especially if they didn’t understand what the problem was. This article discusses how to fix an error Unable to lock the administration directory in Ubuntu and other Debian-based systems.

Cause of Unable to Lock the Administration Directory Error

This problem appears when working with the apt package management utility (or apt-get in earlier versions) during an attempt to install/upgrade any software components.

Starting with Ubuntu 18.04, the error text has been slightly modified, and now it looks like this:

E: Could not get lock /var/lib/dpkg/lock-frontend – open (11: Resource temporarily unavailable)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

unable to lock the administration directory

Perhaps this is due to the fact that a little bit more things that cause the appearance of an error. Error message says that, most likely, the utility is already running. To continue the execution of a new command, it is necessary to complete the previous apt-process in a usual way or force it.

Fix the Problem

First, you need to check if an instance of apt is already running in one of the terminals and wait for it to finish. Forced closure is also often used since it is faster and does not pose a serious danger to the system (first of all, if apt was prone to failure). There are two ways to do this.

Kill the Process

The program can be completed by the built-in kill command, which sends a specific signal to processes. If you do not specify any signal number, then users will get a message that will prompt to complete the process. In case you specify the ninth number, the process stops without warning and allocating time for correct completion.

The kill command can also works with process names, but the following example using ID. Therefore, we first recognize the Process ID (PID):

pgrep apt

fix Unable to Lock the Administration Directory

Here the ID is 1339, it will be probably different for you. Now we need to use this number as a parameter to the kill command with the -9 signal:

sudo kill -9 1339

Note that now the process will become a zombie since the child process was completed, not the parent. It will not occupy memory, but it blocks the entry in the process table under the desired ID. For small and human tasks like apt completion, there is nothing to worry about.

A more correct procedure implies the completion of the parent process. In our case, the sudo apt dist-upgrade command was run.

fix Unable to Lock the Administration Directory error

The process we need is 1337. You already know how to complete them without warning.

Since the parent process is always higher than its child process, this procedure can be performed much faster by creating a fix-apt.sh script with the following contents:


sudo kill -9 $(ps ax | grep apt | head -1 | gawk ‘{print $1}’)

Then give the file a permission to execute and run it in such situations.

Delete Lock Files

How dangerous is the second launch of the package management utility if the system blocks it? Due to the fact that some of the existing files, including those used in the previous copy of the program, can be changed or deleted. This can damage the operation of the affected applications. Therefore, the execution of one apt command at a time is dictated by the security of software components.

There are 3 lock files responsible for this, located in /var/lib/apt/lists, /var/lib/dpkg and /var/cache/apt/archives. Usually, they should be deleted after apt succeeds, but this does not happen under unforeseen circumstances. In this case, they must be deleted manually (with superuser rights, of course) by the rm utility.

You may also like:

How to Install GIT on Ubuntu and Other GNU/Linux S... GIT is a service that facilitates the work of updating various information on a remote server, also by different people. And this is not only about so...
Ubuntu Update Command Keeping your operating system fresh and safe is a priority in PC administration. Distributions often differ in the concept of receiving updates: someo...

Add Your Comment