Generally, there are many errors that appear in the different operating systems, especially in the case of Ubunto. For this reason, in this article we show you the possible solutions for "could not get /var/lib/dpkg/lock" error.

What are the solutions for the "could not get /var/lib/dpkg/lock" error?

This error usually occurs when there is another process that is using the system apt, even when it is in the background, or directly opening the Ubuntu Software center.

It is more common than you think, and for this reason, many users decide to fix this error by placing »sudo rm»However, there are other alternatives that are easier to use, and that quickly help you with the problem.

In summary, this error usually appears when you have the Ubuntu Software Center, Synaptic, or a package manager open in the background, and at the same time you want to perform an update. Next, we leave you the different solutions that you can use.

Close the programs

The first solution that we leave you is to close the programs, but make sure that they are not performing any updates or work on applications, because if so, you will interrupt the process. By closing the programs you ensure that you do not receive any of these common errors in Ubuntu:

  • E: » Could not get lock /var/lib/dpkg/lock – open (11: Resource temporarily unavailable)
  • E: »Cannot lock admin directory (/var/lib/dpkg), is it being used by another process?
  • Could not get lock var lib lib lock dpkg.

Now, in case you do not have any application running, you are surely wondering what is causing the error? And, is that, as already mentioned, this problem appears when another process /var/lib/dpkg It's being used.

And even if you don't realize it, the Ubuntu operating system has in its default settings to enable background application updates. For this reason, when it is starting, it automatically executes the command »apt-get update», and if security updates are available, they will be installed.

So if at the same time you run the command »sudo apt upgrade» the mentioned error will appear.

solutions-for-error-''failed-to-get-/var-/lib/-dpkg/-lock''

Enter the »Software and Updates» application

Another of the solutions that works perfectly is to enter the application of »Software and Updates» that you will find in the applications menu.

solutions-for-error-''failed-to-get-/var-/lib/-dpkg/-lock''-1

The next thing you should do is select the option »Updates», so you can verify that security updates are set to download and install automatically, and if you want to change this, you have to select »Show immediately».

Now, in the next option to check for updates, you need to modify the setting to »weekly or every two weeks» according to your preference. Then, you must enter the password of your user, and in this way, the modification is carried out correctly.

Also, you can make the changes using the command line, opening the terminal and the file /etc/apt/apt.conf.d/20auto-upgradesIn addition, you must write the command:

  • sudo nano /etc/apt/apt.conf.d/20auto-upgrades.
solutions-for-error-''failed-to-get-/var-/lib/-dpkg/-lock''-2

If you place the command correctly, what should appear as original content is the following:

  • APT: :Periodic: :Update-Package-Lists »1»;
  • APT: :Periodic: :Download-Upgradeable-Packages »1»;
  • APT: :Periodic: :AutocleanInterval »0»;
  • APT: :Periodic: :Unattended-Upgrade »1»

To make a modification, and disable automatic security updates, you must place the following:

  • APT: :Periodic: :Update-Package-Lists »1»;
  • APT: :Periodic: :Download-Upgradeable-Packages »0»;
  • APT: :Periodic: :AutocleanInterval »0»;
  • APT: :Periodic: :Unattended-Upgrade »0»;

Now, the last thing you have to do is save the file by pressing Ctrl + O, and to exit press Ctrl + X. After that, you have to reboot your device for the changes to take place correctly.

Wait for all the updates to take place

If you have tried to solve the error with any of the previous options, but it is still presenting itself, another option is to wait for the device to carry out all the updates that are on the list. However, if the process takes a long time, the system is most likely saturated and it is best to change the server where you get the Ubuntu packages.

Remove lock file to apt

In case even the above solution doesn't help you, the only thing left to do is to delete the apt file. And, this process is carried out by typing the following command:

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

Surely, you will also have to delete the lock file in the cache of the computer, and for this, you must type the following commands:

  • sudo rm /var/cache/apt/archives/lock
  • sudo rm / var / lib / dpkg / lock

However, this solution is the least recommended by experts. For this reason, we advise you to try several times with the solutions mentioned above and that this be the last one to be used.