Solutions for “Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?” on Ubuntu

APT, short for Advanced Package Tool is a popular package manager that handles the installation and removals of software on many Linux distribution such as Debian, Ubuntu, etc. Sometimes, you will encounter the following error while trying to run an apt command :

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

There are many causes to this error, and you will see more of them in recent Ubuntu versions. Because the system is more automated, it can automatically use the APT command to check and update necessary packages. The software that can use the APT command in Ubuntu are:

  • Software Center
  • Update Manager
  • Apt link installer
  • The command apt-get or aptitude command line utilities.
  • Synaptic Package Manager

This article is going to explain the cause of this problem and how to quickly fix it.

Why does "Unable to lock the administration directory (/var/lib/dpkg/)" happens?

For safety reasons, apt only allows one installation going at any given time. During the installation and removal of packages, apt stores its status in /var/lib/dpkg.

Before any other apt process begin an operation, it will check the path to see whether the system is busy or not.

Unable to lock the administration directory (/var/lib/dpkg/) means that there is an operation on the system going underway and your current command cannot proceed.

1. Fastest solution : Restart the computer

Most of the time, the lock on /var/lib/dpkg/ is because the system is updating itself. So if you're not in the middle of a productivity session and cannot be interrupted, one simple restart could solve the problem.

You can do it right inside the terminal by typing

sudo reboot

2. Safe solution : Wait it out

If you're not in a hurry, the safest option in this situation is to wait until the current process that are using /var/lib/dpkg completed. After that, you can proceed with whatever you want. Most of the time, an update takes place in about under 10 minutes (with a decent internet connection).

Curious about what is taking over your system? Type this in the terminal to find out :

ps aux | grep apt

3. Kill the processes that are using /var/lib/dpkg

Find out which process is using /var/lib/dpkg

If two solutions above does not fix the problem, try examining the running process:

ps aux | grep -i apt

The command will look for any apt process running and its name, command so that you can figure out what is happening. Look for something like this :

/usr/lib/apt/apt.systemd.daily update

list of services using dpkg

In this case, apt.systemd.daily indicates that the system is doing the daily update. No action is required in this situation other than wait for it to finish.

Sometimes, you will see other things comes up in the terminal :

root    2651  0.0    0.0    72948 4312  pts/0  S+    15:03  0:00   sudo apt-get remove docker -y

The output above means apt is in the middle of removing docker but then something happens and it hangs there. Notice 2651 in the output as it is the process ID, you will need this later.

If no apt process comes up in the terminal output, you need to check for dpkg processes:

ps aux | grep -i dpkg

Look for something suspicious and remember the PID of the process like mentioned above.

Kill the process that is hanging

Once you've obtained the PID of the process that is hanging in the middle of an operation, you could terminate it using the following command

sudo kill <process_id>

If it doesn't do the trick, then force it to stop by sending -9 option

sudo kill -9 <process_id> 

Delete lock files

apt uses several lock files to store its status

  • /var/lib/dpkg/lock
  • /var/lib/dpkg/lock-frontend
  • /var/lib/apt/lists/lock
  • /var/cache/apt/archives/lock

As you've ended the process when it wasn't finished, the lock files doesn't get cleaned properly so we must do it manually by typing these in the terminal:

sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock

After removing these lock files, the error should be fixed.

Click to rate this post!
[Total: 0 Average: 0]

1 thought on “Solutions for “Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?” on Ubuntu”

Leave a Comment