Solutions to the error "could not get lock / var / lib / dpkg / lock"

Could-not-be-blocked

El error "could not get lock / var / lib / dpkg / lock" is quite common in Debian, Ubuntu and derivatives and this it is usually launched when another process that uses apt it is running either in the background or when you have the Ubuntu software center, Synaptic and others open.

It is because of that in this article we will see how to solve this error despite having applied the solutions to the aforementioned.

Commonly in despair of seeing this error and not being able to do anything with apt, they choose to apply the classic "sudo rm" which is the least indicated option.

But before going directly to this, we can see that other causes are those that have blocked the use of apt.

Solutions

How to Live Aligned with mentioned above this error is usually displayed when you have apt running in another processTherefore, if you want to do an update or installation from the terminal and you have your Ubuntu software center, Synaptic or a package manager open in the background, these are the main cause of this error.

Solution 1

The first solution is to close these programs as long as they are not doing any work as an update or application installation, because if so it is highly recommended to wait.

With this, we will stop receiving the error of:

E: No se pudo obtener el bloqueo /var/lib/dpkg/lock - abierto (11: El recurso no está disponible temporalmente)

E: No se puede bloquear el directorio de administración (/var/lib/dpkg), ¿lo está usando otro proceso?

no se pudo obtener el bloqueo var lib lib bloqueo dpkg

But what if you don't have any of this running?

The error message already gives you a clue to the cause of the problem: another process / var / lib / dpkg / is being used.

Esto It is because Ubuntu, by default, enables background updates for security update.

When Ubuntu finishes booting, it automatically runs the apt-get update command.

If security updates are available, it will install them in the background.

So if they run the sudo apt upgrade command at the same time, the above error is displayed.

This is usually quite rare to happen, but it has happened to all of us, because when we turn on the computer and want to make some movement with apt, the terminal throws us this error.

Here it is recommended to let Ubuntu make the corresponding updates.

Solution 2

ubuntu-18.10

To solve this problem just go to the "Software and Updates" application which we will search from our applications menu.

And in the window that opened, we must go to the Updates tab, among the options that show us by default, security updates are downloaded and installed automatically to change this we must change to "Show immediately".

In the part of checking updates we change it to "weekly or every two weeks" here is your choice.

Then enter your user password for this change to take effect.

Similarly you can achieve the same results from the command line. In your terminal, open the /etc/apt/apt.conf.d/20auto-upgrades file:

sudo nano /etc/apt/apt.conf.d/20auto-upgrades

The original content is as follows:

APT::Periodic::Update-Package-Lists "1";

APT::Periodic::Download-Upgradeable-Packages "1";

APT::Periodic::AutocleanInterval "0";

APT::Periodic::Unattended-Upgrade "1";

To disable automatic security update, change them to:

APT::Periodic::Update-Package-Lists "1";

APT::Periodic::Download-Upgradeable-Packages "0";

APT::Periodic::AutocleanInterval "0";

APT::Periodic::Unattended-Upgrade "0";

They save the file with Ctrl + O and exit they must press Ctrl + X.

Later we restart our equipment.

Solution 3

Could-not-be-blocked

Finally, if you still continue to receive this error, do not despair, the recommendation is that you let your team perform its updates, but if this takes too long, possibly the mirror you have configured is saturated or down.

So it is recommended that you change the server from where you are obtaining the Ubuntu packages.

Solution 4

At the end of all this if the problem persists, you can choose to apply the definitive solution which is to delete the file that is blocking apt.

They can remove the lock file with the following command:

sudo rm /var/lib/apt/lists/lock

They may also need to delete the lock file in the cache directory

sudo rm /var/cache/apt/archives/lock

sudo rm /var/lib/dpkg/lock

But they should know that this last method is the least recommended.


2 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Juan Carlos said

    Hi, thanks for the article.
    That error is annoying, I solved it with the first option.

  2.   Adrian said

    Or better wait a few minutes, hours, and run it again