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?


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.


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.

  • Good point, I didn't think of that. Apr 15 '15 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.