Could not get lock /var/lib/apt/lists/lock

This is the code I’m running on the circleci machine:

sudo rm -rf /opt/circleci/.nvm            
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y -f nodejs

I’m getting this error:

## Installing the NodeSource Node.js 10.x repo...


## Populating apt-get cache...

+ apt-get update
E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/
Error executing command, exiting

Reading package lists... Done


Building dependency tree       


Reading state information... Done

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nodejs : Depends: libv8-3.14.5 but it is not installable
E: Unable to correct problems, you have held broken packages.
/home/circleci/project/edcode/.circleci/setup_node.sh: 6: /home/circleci/project/edcode/.circleci/setup_node.sh: npm: not found
Exited with code 127

Search for it on the forum, this has been asked before. :smiley:

@halfer

Can you share the other post? I’m having trouble locating it.

Yes; I didn’t have time before. I will look now.

Edit: this is the one I had in mind. Second answer for “could not get lock”.

Ah, it’s a different file, so a search didn’t find it.

@hassaans please let us know if the above thread doesn’t help you.

1 Like

I encountered this issue today. For anyone who was unable to use the suggested fixes in that thread, as I was, I’ve found a solution:

sudo killall -9 apt-get || true && \
            sudo apt-get update && \
            sudo apt-get install -f whatever-packages

The killall -9 stops any rogue apt-get procs from continuing and unlocks the package list so you can install your dependencies. The || true is a failsafe in case there aren’t any procs.

Things that didn’t work for me:

  • switching to an older machine executor (I’m using circleci/classic:201808-01 )
  • adding a sleep
  • trying to install the packages before checking out my repo
6 Likes

@katiekeel This worked! Thanks a lot!!!

1 Like

No problem. I wouldn’t necessarily do that on my own machine as it could cause unexpected corruptions, but since Circle VMs are ethereal it’s a relatively safe experimentation.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.