4

I'm trying to execute the command sudo apt-get -y install linux-headers-rpi to install this driver for a pm sensor. However, my raspi gives me this output every time when I execute this command:

E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?

I've searched through other post on the forum, and they said that it should be ok once I've reboot it or killed the process that's occupying the file. I did it, but it didn't work. Help?

5 Answers 5

5

First check if there is a dpkg process running, ps afx|grep dpkg.

If thats the case, kill it with sudo killall dpkg.

Remove the lock file with sudo rm /var/lib/dpkg/lock

That should do the trick.

2
  • 1
    So I first checked if there are any processes running: ps afx|grep dpkg. Result: '18271 pts/0 S+ 0:00 _ grep --color=auto dpkg'. Then I removed the lock file 'sudo rm /var/lib/dpkg/lock'. Now it gives me this: 'E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?'
    – Marc
    Commented Feb 18, 2018 at 10:48
  • google "/var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root"
    – MatsK
    Commented Feb 20, 2018 at 7:01
3

I ran into this problem recently, and it turns out the issue was that I was only sudo-ing one of the chained commands I was using.

I was using sudo apt-get update && apt-get install -y libssl-dev libffi-dev python3-dev build-essential

But I should have been using sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python3-dev build-essential

(note the second sudo)

1

sometimes the error message gives you the pointer to the problem. "Are you root" means you may be trying to run a command without superuser privilege. try running the command preceded with sudo e.g. sudo <command>

1
  • 1
    Please notice that the OP tried the command: sudo apt-get -y install linux-headers-rpi.
    – Ingo
    Commented Mar 1, 2019 at 11:11
0

This one is old, but I recently had this problem with a freshly written iso.

Expanding the filesystem to use the entire SD card did the trick for me.

As apt-get upgrade might be quite expensive (counting storage). I assume this has been the problem.

0

This problem happen with me but finally it solved do :

ps afx|grep dpkg
sudo killall dpkg
sudo rm /var/lib/dpkg/lock

Run your process you want, if isn't work follow next step

apt --fix-broken install

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