Want to install monitoring agent but,I am getting Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

April 11, 2018 1.7k views
Ubuntu 16.04 Apache

I am trying to install monitoring agent by running the command

curl -sSL https://agent.digitalocean.com/install.sh | sh

But I am getting the response

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 totally have no idea what this is,has anyone come across such issue or knows how to fix this?

Thank you.

3 Answers

You either have to run that as root, or prefix the command with sudo

This error indicates that another process is using the package system (apt). Since this controls the installation and update of software on your platform it’s limited to a single process at a time to prevent it being corrupted.

You can use ps afx|grep dpkg to check if there is still a process running at the same time. sudo killall dpkg will stop all running dpkg processes.

sudo rm /var/lib/dpkg/lock can be used to manually remove the lock if there isn’t any other process using it. This can happen if another process crashed earlier without releasing the lock.

As @Cronus89 said, you will have to either run these and your other commands as the “root” user or use sudo in front of your command.

  • I had the same error and followed the steps above. Now I get

    E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.
    
    • This is expected when killing a dpkg/apt process in this way. You should run the command recommended by the message which will reset your dpkg configuration and then you should be all set.

If you are doing this very early in the droplet creation process, eg. from a cloud-init script then the reason might be the fact that DigitalOcean’s local agent is also doing an apt-get update right after the droplet comes alive.

root       817  0.0  0.2   9576  2644 ?        S    07:56   0:00  \_ /bin/bash /var/lib/cloud/instance/sem/do_agent
root       842  2.0  0.6  35572  6728 ?        S    07:56   0:00      \_ apt-get -qq update
_apt       848  0.0  0.4  36224  5032 ?        S    07:56   0:00          \_ /usr/lib/apt/methods/http
_apt       849 14.0  0.4  36224  5044 ?        R    07:56   0:00          \_ /usr/lib/apt/methods/http
_apt       857  0.0  0.4  31856  4688 ?        S    07:56   0:00          \_ /usr/lib/apt/methods/gpgv
_apt       924  0.0  0.8  40104  8824 ?        R    07:56   0:00          \_ /usr/lib/apt/methods/store

The solution might be to wait a bit before doing the update or try again a few times until it succeeds.

Have another answer? Share your knowledge.