0

I have a script that uses apt heavily and currently it faces a locking issue, as:

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?

I want that apt tries to get the lock other than aborting. Is it possible?

Breno Leitão
  • 188
  • 1
  • 6
  • Why do not use a query in your program and wait with the further execution until a lock is possible again? – A.B. Apr 14 '15 at 19:10
  • possible duplicate of [Is there a way to install packages via a a queue even when there is another instance of an installation or upgrade is running?](http://askubuntu.com/questions/92271/is-there-a-way-to-install-packages-via-a-a-queue-even-when-there-is-another-inst) – muru Apr 15 '15 at 18:27
  • Or http://askubuntu.com/questions/132059/how-to-make-a-package-manager-wait-if-another-instance-of-apt-is-running – muru Apr 15 '15 at 18:27

2 Answers2

2

As far as I know, getting apt to not lock is impossible. The error is happening because the script is trying to run multiple apt sessions simultaneously. I think it would be best if you could modify the script so that apt operations are run after each other, in a queue maybe.

Wilhelm Erasmus
  • 718
  • 5
  • 24
1

in addition to @Wilhelm's advice (which is good) if you are left with a stale lock file that will not go away (this happens some times) you must remove it manually.

sudo rm -rf /var/lib/dpkg/lock

But be very careful that you have the path exactly correct as the sudo rm -rf will remove files (even system files) in use if you point it to them and can thus permanently break your system.

Wilhelm Erasmus
  • 718
  • 5
  • 24
Charles Wright
  • 252
  • 2
  • 5