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.

How To: Update A Single Package In Ubuntu

Today’s article should be short because it’s late in the evening and I have decided to write about how to update a single package in Ubuntu. It’s an easy topic to write about, as there are really just a couple of choices. It shouldn’t be complicated and, for the most part.

First, let me state this…

I firmly believe that you should keep everything updated and updated the minute the update is available.

HOWEVER…

That assumes a perfect world. We do not live in a perfect world. We live in the real world. Because of this, people delay updates for various reasons. The biggest delay I can think of at this hour of the night is the delays added in the business world.

Rather than push an update to production, they’ll run it through testing first. It can take quite a while before an update makes it into production.

The reality is that many of our updates are security updates. As a byproduct of their update policy, at any given time they’re running insecure software. I understand why they’d do this. They don’t want things to break. They certainly don’t want public-facing things to break.

Again, I can understand why regular people follow a similar process. They’ll wait and watch to see if the updates cause problems for other people. But, that’s like waiting for the first person to jump in the river to see if the water is cold.

In all my years of using Linux, I’ve had updates bork the system fewer times than I have fingers on one hand. I’ve had updates bork the system so completely that it hoses everything exactly zero times. As in, not once was I screwed over by an update that really did any damage.

But…

Again, I can understand those who would rather be cautious.

This article is for you. It’s for you people who want to update a single package in Ubuntu. It’s for those people who do what they must in order to maintain a stable system.

This isn’t just applicable to Ubuntu. I tend to use Lubuntu and, as such, am a fan. So, I used Ubuntu in the headline. This applies equally to Debian, Mint, and other Ubuntu derivatives. It should even work in derivatives of derivatives. It’s pretty basic stuff.

Update A Single Package In Ubuntu:

So, you might be able to do this with a GUI. I don’t actually know and I didn’t test to see if there was a way to do so graphically. Check your software manager while the rest of us open a terminal. You can (more often than not) open your default terminal by pressing CTRL + ALT + T.

With your terminal now open, you need an application to update. If you’re a good netizen, you hopefully don’t have many upgrades available. You can check and see by running this command:

You can then get a list of applications that can be updated, assuming there’s an application that can be updated, with the following command:

The next step is to use one of the following two commands to update a single package in Ubuntu (neither of which are all that difficult):

Yes, that looks like it’s going to install a new application, but you substitute the <package_name> with the package name that you want to update in Ubuntu. The ‘install’ will happily upgrade to the next passage.

The next one is bit more jargony. Jargon-y? Maybe? It’s more complicated looking (but easy enough to memorize). So, if you want to update a single package in Ubuntu, this too should also do the trick:

Once again, you replace the obvious with the obvious. Just doing so would help you sort out how to update a single package in Ubuntu. Either of these commands should work, so you do have a choice.

Closure:

As I said, it’s not going to be all that difficult to update a single package in Ubuntu. You have a choice in commands. While I think it’s best to avoid all update delays, I do understand why you might want to be more cautious.

I go full blast at updates, but I’ve lately been a bit slow about major upgrades. In my case it’s a bandwidth issue. I had one box running like Linux Mint 20 or something like that…

Wait, it still says 21 is the version – but I’m quite literally nearing the end of the upgrade process. That may have already changed. I was so far behind that I needed more than 4 GB worth of downloads. When I’m done we’ll have an OS that’s missing almost all the stuff I installed on top of it! 

It can sure be a pain in the butt. Alas, as least I’m not trying to update a single package in Ubuntu!

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.

Extract Files From .DEB Files

Today we’ll be discussing a rather simple subject, limited to just the curious and tinkerers, about how you extract files from .deb files. The folks who want to know this information will likely be the intellectually curious or those who are doing so for scholarly, academic approaches. Then, of course, the folks who like to tinker might also be curious.

Let’s get this out of the way first…

The .deb file extension is also a format of the files. These files are software packages, handled by dpkg I suppose, and valuable only for those systems that are based on Debian (though I’m sure there’s an exception out there, it won’t be with a popular distro).

You see and use these files quite often if you’re using a distro based on Debian. Some examples of distros derived from Debian would be Ubuntu (and the Ubuntu family of official flavors), Linux Mint, elementaryOS, and a whole lot more. If you’re using ‘apt’ or ‘dpkg’ in the terminal, you’re almost certainly using a Debian derivative.

This means that this article isn’t appropriate for everyone. If you’re using a distro with a different package manager, this article won’t apply to you. Should you want me to cover that distro and think it’d make a good article, you can contact me. If you’re unfamiliar with Debian and its derivatives, you can read this Wikipedia page about the .deb file format.

The tool we’ll use to extract files from .deb files is known as ‘ar’ and should be installed by default. Any distro using .deb files, unless it’s a very stripped-down version, will contain the ar application. If you check the man page (man ar), the naming section should indicate that it’s a suitable application for this task. More specifically, it says:

ar – create, modify, and extract from archives

If you check the actual description on the man page, it says this:

The GNU ar program creates, modifies, and extracts from archives. An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive).

So, we have the right tool for the job. It’s a pretty useful tool that doesn’t get used all that much. The chance to introduce it to some new people is quite a privilege and I appreciate all of you who read this blog.

By the way, it has come to my attention (thanks to WizardFromOz from Linux.org’s forums) that you’ll not have ar installed by default. You’ll need to install it. Seeing as we know you’re using this package manager, you can install it by installing binutils. The command to do so is:

Speaking of this blog, I’ve been getting a great deal of ‘blog comment spam’. Automated attempts are pretty well locked down and prevented, so this means that people are doing this manually. They’re possibly even solving reCAPTCHA to do this and this is entirely a waste of time. It takes me mere seconds to deny the comments and the comments are never published.

I only publish comments that are acceptable (and I’ve even published some derogatory comments, just because I didn’t want to censor someone’s opinion – but I will censor spam). So, they’re not getting any return on their time and labor. Removing them annoys me. I get so few comments that I could almost justify disabling them entirely, but I want folks to be able to discuss any of my articles – and to correct me when I’m wrong or when I omit something important.

Anyhow, enough of that… Let’s just get into the article itself…

Extract Files From .deb Files:

Yes, we’ll be using the terminal. If you do not want to use the terminal, this is quite easy to do in the GUI. Simply open up your file manager, navigate to where you’ve stored the .deb file, right-click on the file, and choose to extract the files. You can also choose to open the file with your GUI archive manager and then extract just the files you want to extract. It’s pretty simple!

Now, for those of us who want to do this in the terminal, just press CTRL + ALT + T, and your default terminal should open. Not every distro has this keyboard shortcut as a default, and that’s just horrible. It really should be universal and your distro (should this shortcut not already work) will likely have a way to map those keys to open a terminal. 

With your terminal now open, navigate to where you’ve downloaded a .deb file. If you do not have a .deb to play with, you can do this:

With your existing .deb file, or with your freshly downloaded .deb file, we can now extract files from .deb files. The command would look similar to this:

If you use the v flag (notice the lack of the - part of the flag) then it’ll be verbose – meaning it will tell you the output. If you don’t need the output, you can skip it, just know that each .deb file should contain three files and that these three files should all be consistently named.

Should we put this all together, your command would look something like this:

Or, if it’s in a folder of its own, without any other .deb files, you can cheat and just use a wildcard – like this:

The output of that command would look something like this:

And, if you navigate to the directory with your GUI file manager, you should see something that looks quite similar to this:

the results if you extract the files from the Google Chrome .deb
Assuming the .deb follows standards, it’ll look just like that, regardless of the application.

This should be consistent across all the various .deb files you extract. They’ll contain those two additional compressed files and a ‘debian-binary’ file. If you’re interested in what’s inside those ‘tar.xz’ files, you’ll have to use a search engine or wait for another article, because that’s more than I am going to get into.

I may still write a full article, but the way to extract those ‘tar.xz’ files is to do it like this:

I trust you can figure it out from there. It’s a bit different from how you extract files from a .tar.gz file. So, it should maybe get an article all its own. This tiny bit of information won’t get indexed properly, so a whole article will make it easier to find and follow. 

Closure:

Well, this appears to be another long article. It doesn’t take all that much more time to write articles of this length. I’m kind of doing this as an experiment. I am interested in seeing how Google reacts to these longer articles, with more information and with more code and pictures as examples. I’m being optimistic because I don’t mind making the articles longer. 

I have a ‘secret weapon’ I’ve been using since January of this year. That makes it much easier. I plan on doing an article about said secret weapon at some point, but I need to get my ducks in a row first. I hope it’ll be interesting and I’ll likely publish it on a day off so that it doesn’t stop the flow of regular articles. (The spice must flow!)

As always…

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.

How To: Decompress tar.bz2 Files

Today’s article will be simple enough, though it will have limited application, as we discuss how to decompress tar.bz2 files. While this is certainly suitable for a newbie and easy enough to learn, many folks will just choose the GUI route.

Of course, you’re not always able to use a GUI. Sometimes there’s no way to do this graphically and you’ll have to do this in the terminal – perhaps over SSH. In fact, with my crappy bandwidth, I like to upload compressed files and then extract them on the server itself. This sort of thing works for me.

We have already talked about how you go about compressing and decompressing .bz2 files. You can read that article here:

How To: Compress And Decompress .bz2 Files

This time we’re going to be working with ‘tar.bz2’ files – and decompressing these files is different than what you’ll have learned from the previous article.

What is ‘tar’?

A tar file stands for ‘Tape Archiver’ and is a compression method as old as time itself. Well, probably not that long – but a very long time. It’s sometimes referred to as a ‘tarball’ and Wikipedia tells me that it has been around since early 1979.

Here’s a good quote from Wikipedia:

The archive data sets created by tar contain various file system parameters, such as name, timestamps, ownership, file-access permissions, and directory organization.

The blurb goes on to mention that POSIX has supplanted tar in favor of pax, but when was the last time you saw a .pax file? So, tar is still widely in use.

The man page describes tar as:

tar – an archiving utility

Which is exactly the kind of thing we’re looking for. Imagine that?

What is .bz2?

If you read the link above, you’d know the answer to this question. I assume my readers are creatures of habit, so they’ve done no such thing. They’re probably skipping this section entirely and reading just the middle of the article.

Anyhow, in the previous .bz2 article, I mentioned this:

If you don’t already know, .bz2 files are bzip2 files. You’ll find that bzip2 is an opensource compression program that gets some regular usage, and you’ll sometimes find downloaded files that are compressed with this format. You may also, for compatibility reasons, want to compress files with bzip2 to share with other users who are already set on using the .bz2 format.

That sums it up nicely, though you don’t have to worry about that. See, with this particular command and these particular tar.bz2 files, you can decompress (extract) the files in one fell swoop. 

Just for the record, you should also know that the bzip2 man page defines itself like so:

bzip2, bunzip2 – a block-sorting file compressor, v1.0.8

Your man page might be different, saying that it’s a different version. Either way, that’s what bzip2 is and that’s what it’s used for. 

So, with all that in mind, we can get to the important bits of the article…

Decompress tar.bz2 Files:

As I mentioned in the intro, you can likely do this with your built-in GUI file extraction tool (often file-roller) easily enough. However, again as suggested in the intro, we’ll be doing this in the terminal. In most cases, you can press CTRL + ALT + T to open the terminal.

With your terminal open in the correct directory, you can start by listing the files in the archive without actually decompressing them. That command would look like this:

That will happily spit out a list of all the files included. If you want, you can make the output more verbose by adding the -v flag, so that it’d be tar -tvf for example.

Next, I assume you want to decompress the tar.bz2 files, that is to extract the files within. To do that, you’d want this command:

Finally, I’ll give you a fun command. Let’s say you only want to extract files of a certain type, that is with a certain extension, from your tar.bz2 file. Well, you can do that and it’s easily done. Just use this command:

That command would decompress and extract all the files with .jpg as their extension. You can use any extension there, being sure to use the * to indicate a wildcard even though you already specified it with the –wildcard flag. It is what it is.

There’s more that you can do, but those are the ways I figure most folks are going to decompress tar.bz2 files. Just be sure to check the man page (man tar) to learn more about the command.

Closure:

Well, for better or worse, my articles have been pretty verbose lately. Yes, yes it does tell me how many words are in each article. I’m not sure why I ended up being more verbose lately, but I think it’s a good trend.

Anyhow, today we learn how to decompress tar.bz2 files in the Linux terminal. It’s a useful skill to have and a good tool to toss into your Linux toolkit. You never know when you’re going to need to use these commands, but there may come a time when you do – and you can refer back to this article to learn how.

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.

Open ‘WebP’ Images In Linux Mint

Today’s article shouldn’t be all that complicated, as we’re just going to touch on how to open WebP images in Linux Mint. I am not sure how many people this will help, but it seems like a good idea for an article. It’s also something I’ve recently dealt with, so it’s fresh in my memory. So, if you want to open WebP images in Linux Mint, read on!

Why Linux Mint? Well, because I know it works in Linux Mint. I just happened to be using one of my Linux Mint systems when I encountered this problem. I’m positive this works in other distros, but I’ve only tested this with Linux Mint.

The Story:

I wrote an article about how to disable window grouping in Lubuntu. A lovely friend pinged me to a question on AskUbuntu that involved this subject, suggesting that I answer it. I decided to answer the question.

Being lazy, I wanted to answer the question using the same screenshot I’d used in the article. I did the rational thing and downloaded the file from the linked page. 

The image had a border around it and I wanted to remove that border. I went to open the file with the WebP extension in my image viewer only to learn that there was no native support. When I opened the file, it showed the image in a new browser tab.

I could open the file in XnView and be done with it, but that wasn’t good enough. I wanted to be able to open the file natively, in my default image viewer. Alas, time was of the essence and I put that task aside so that I could answer the question. Later, I’d return to the problem and find a solution.

For reference, this is what it looked like when I tried to open a WebP file with the default image viewer:

there's no webp support
As you can see, that’s hardly a productive image.

It would happily show the image in the browser I had open because the WebP format is meant for the internet. That’s hardly useful and opening a browser to view an image just seemed like a step too far.

If you don’t know what WebP files are, you see and deal with them constantly – even if you don’t know, you can read the Wikipedia article about WebP files. They’re image files that are optimized for web use.

I wanted to find a way to open WebP images natively in Linux, specifically Linux Mint. My quest sent me down several false trails and I eventually found a solution that worked. This article shares that with you…

Open WebP Images In Linux Mint:

That’s right, there is a solution. To do this, which is open WebP images, we will need to have an open terminal. It’s okay, you only need it for a few commands. So open your terminal emulator. In many cases, you can just press CTRL + ALT + T.

With the first command, we’re going to add a repository:

Follow the directions and add the repository. Then you need to update the list of available software, like so:

Finally, install the following software with this command:

You don’t need to do anything else. That’s it. That is all you need to do. When you next open a WebP image in Linux Mint, you should be able to do so just fine with your default image viewer.

It should look something like this:

when you've completed these steps, you should be able to view WebP images in your default image viewer
See that image? That right there smells like success! It’s a WebP image!

If you click on that image, you can see that it’s a WebP image by looking at the title bar. The application should look familiar. It should look exactly like the default image viewer included with Linux Mint.

And now you know…

Closure:

That’s all there is to it. Linux is great like that. Sure, it took a bit of digging but there was a solution to my problem. Once I knew the correct solution, it was easy to implement. If you want to open WebP images in Linux Mint, you can do exactly that – without all that much effort. If you dream and work hard enough, someone else will have already done all the work and you can just use their software to accomplish your goals!

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 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.