Dealing With “Could not get lock /var/lib/apt/lists/lock”

Today’s article is a rather specific article, where we examine a couple of ways to deal with the message “Could not get lock /var/lib/apt/lists/lock”. This is an error message that you’ll get when something is already updating (or installing) and you try to install something else or if you try to perform updates.

Basically, when you update something, apt will lock a file so that nothing can interfere with it. This is a good thing, ensuring your updates go smoothly. This is something you want to have to happen.

However…

Things don’t always go according to plan. Things may freeze, things may take too long, and things can stop the upgrade (or update, let’s use those words largely interchangeably). You may find yourself coming across this message and not knowing what to do.

A bit on update and upgrade

First, obviously, this article only applies to distros that use ‘apt’ as their package manager. So, that’s Debian, Ubuntu, Mint, and many more that are derived from Debian or Ubuntu.

You have on your computer a database of software available in the repositories you’ve enabled. Then you update this database software with ‘sudo apt update‘. You then upgrade your software when you run ‘sudo apt upgrade‘. So, in the very specific terminology used, there’s a difference between update and upgrade. I know this, but will use the words interchangeably. 

As mentioned, when you’ve started this process (that is the updating of the database) you’ll be frozen out of further apt commands that can act on the system. You can still run queries like ‘apt-cache search foo‘ but you can’t install or uninstall software while this process is happening. The same is true during the upgrade portion of the process.

Well, that’s when you’re going to get this error message.

For example, I recently had to update a Linux Mint system and the update process was horrible – but mostly because it didn’t seem designed to work with bandwidth like mine.

There were constant timeout warnings even though things were still downloading. Things would also freeze entirely and it was during this that I realized I should write an article about what to do when you get the message “Could not get lock /var/lib/apt/lists/lock”. After all, I was killing that process like an assassin in a video game. I showed no mercy!

NOTE: The correct thing to do is wait. If waiting doesn’t work and much time has passed, the next correct thing to do is reboot. After you’ve rebooted, you should try the update again and follow any directions it might give you.

YOU SHOULD NOT DO THIS!

I don’t always follow directions well. Nor do I always do the right thing. This is hardly the first time I’ve given you answers about how to do the “wrong” thing right. This probably won’t be the last time I’ve told you how to do things that are generally considered a bad idea, sometimes an especially bad idea.

With that said and done…

Fix “Could not get lock /var/lib/apt/lists/lock”:

You’re going to want an open terminal for this. Yes, a terminal. You should be used to that by now. The terminal is a handy application and we use it often. In most cases, you can just press CTRL + ALT + T and your terminal should open.

We want to get rid of the message “Could not get lock /var/lib/apt/lists/lock”. and I’ll cover a couple of quick and easy ways to do this, meaning you can (generally) start the process all over again. With your terminal, we’re going to find the PID – that is Process ID – and kill it.

You can read this article:

Find An Application’s Process ID (PID)

Or you can skip that article…

We already know that we’re interested in apt’s PID, so we just run this command:

Take the output from that and enter it in the following command:

Of course, that’s the fun way. You can actually use a much easier command to deal with the “Could not get lock /var/lib/apt/lists/lock” message. It’s not nearly as fun, but it should work every time. Try this command:

That one command should always work and is fairly easy to remember. You just take the path of the lock from the command, elevate your permissions, and remove the lock. It’s not unlike using lock cutters on a real-world lock, but requires much less physical effort!

Again, I highly suggest you resolve this message in the proper manner. Wait a while, reboot if nothing changes over time, and then try the update again so that you can follow any directions it gives you. That’s the smart way to deal with this.

Closure:

Yup… Here I am giving bad advice on the internet. I figure folks might just want to do this. If they want to do this, they might as well have good directions. This isn’t the correct way to deal with “Could not get lock /var/lib/apt/lists/lock” but it’s a way of doing so. You could end up with some currupt files and impropperly installed software, so you really should not do it this way, but it’s your computer.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!
icon

Author: KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.