Could not open lock file /var/lib/apt/lists/lock – open (13: Permission denied)

I’m trying to update to node 7.x through the terminal on my raspberry pi and I keep encountering this error. The command I’m using is:

sudo curl -sL https://deb.nodesource.com/setup_7.x | bash -

Running this command as root doesn’t work so I tried to see if apt-get was being used by any other processes.

ps aux | grep apt
pi        1295  0.0  0.1   4272  1848 pts/0    S+   06:24   0:00 grep --color=auto apt

This is all I get. Ultimately, (although it was initially advised not to do so), I tried removing the files and running the command again.

sudo rm /var/lib/apt/lists/lock && sudo rm /var/lib/dpkg/lock

Now neither one of these files no longer exists and I still receive the same error when trying to use curl. I also tried to kill that one process and I still get the error.

Asked By: Alphatron

||

The problem is that you sudo curl but not the bash call which call apt.
just run it fully as root, for example :

sudo su
curl -sL https://deb.nodesource.com/setup_7.x | bash -

or you can do something like

wget https://deb.nodesource.com/setup_7.x
chmod +x setup_7.x
sudo ./setup_7.x
Answered By: M4rty

Remove the lock file

sudo rm /var/lib/apt/lists/lock

Then run the command as root or add sudo -E as follows :

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
Answered By: GAD3R

I resolved a very similar issue in a Dockerfile, by adding ‘sudo’ after the pipe:

RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -

Answered By: Keagan Fouche

for me worked

sudo su
curl -sL https://deb.nodesource.com/setup_7.x | bash –

thank you whoever posted it

that was my problem:

"Could not open lock file /var/lib/apt/lists/lock – open (13: Permission denied)"

Answered By: BenSusaj
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.