How To Solve Error: “E: Could not get lock /var/cache/apt/archives/lock – open (11: Resource temporarily unavailable) E: Unable to lock directory /var/cache/apt/archives/” On Debian 7

Today i have keep getting an annoying error when i try to install some python libraries.

"E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/cache/apt/archives/"

This is the first time i got this error and i don’t have any clue how to solve this. I googled a bit and found the solution after spending almost an hour. I wanted to share with Unixmen readers. Here you go.

Problem:

Here what i did to install to python libraries.

# apt-get install python-twisted

Sample output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  python-crypto python-openssl python-pam python-pkg-resources python-pyasn1
  python-serial python-twisted-bin python-twisted-conch python-twisted-core
  python-twisted-lore python-twisted-mail python-twisted-names
  python-twisted-news python-twisted-runner python-twisted-web
  python-twisted-words python-zope.interface
Suggested packages:
  python-crypto-dbg python-crypto-doc python-openssl-doc python-openssl-dbg
  python-distribute python-distribute-doc doc-base python-wxgtk2.8
  python-wxgtk2.6 python-wxgtk python-twisted-bin-dbg python-tk python-gtk2
  python-glade2 python-qt3 python-twisted-runner-dbg
The following NEW packages will be installed:
  python-crypto python-openssl python-pam python-pkg-resources python-pyasn1
  python-serial python-twisted python-twisted-bin python-twisted-conch
  python-twisted-core python-twisted-lore python-twisted-mail
  python-twisted-names python-twisted-news python-twisted-runner
  python-twisted-web python-twisted-words python-zope.interface
0 upgraded, 18 newly installed, 0 to remove and 65 not upgraded.
E: Could not get lock /var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/cache/apt/archives/

Solution:

If you encounter with the same error, do the following steps.

Run the following command to unlock the apt package managers.

# rm /var/cache/apt/archives/lock

Now update the sources list using command:

# apt-get update

Finally try again to install the packages you want.

# apt-get install python-twisted

Sample output:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  python-crypto python-openssl python-pam python-pkg-resources python-pyasn1
  python-serial python-twisted-bin python-twisted-conch python-twisted-core
  python-twisted-lore python-twisted-mail python-twisted-names
  python-twisted-news python-twisted-runner python-twisted-web
  python-twisted-words python-zope.interface
Suggested packages:
  python-crypto-dbg python-crypto-doc python-openssl-doc python-openssl-dbg
  python-distribute python-distribute-doc doc-base python-wxgtk2.8
  python-wxgtk2.6 python-wxgtk python-twisted-bin-dbg python-tk python-gtk2
  python-glade2 python-qt3 python-twisted-runner-dbg
The following NEW packages will be installed:
  python-crypto python-openssl python-pam python-pkg-resources python-pyasn1
  python-serial python-twisted python-twisted-bin python-twisted-conch
  python-twisted-core python-twisted-lore python-twisted-mail
  python-twisted-names python-twisted-news python-twisted-runner
  python-twisted-web python-twisted-words python-zope.interface
0 upgraded, 18 newly installed, 0 to remove and 65 not upgraded.
Need to get 3,697 kB of archives.
After this operation, 16.9 MB of additional disk space will be used.
Do you want to continue [Y/n]?

Voila! Now the package manager lock has been released and you’ll be able to install the packages without any issues.

Cheers!