1. Overview

Libraries are an essential component of any Linux system. This is because they provide various functions and routines which are reusable by multiple software applications. So, as a Linux administrator, keeping track of library versions is crucial for ensuring compatibility between the library and its dependent software.

In this tutorial, we’ll discuss how to check for the version of a library using the dpkg and apt commands on the command line. These commands contain a variety of options that we’ll also discuss. We’ll mainly focus on the Debian and Ubuntu Linux distributions.

2. Using the dpkg Command

The dpkg command is a low-level package management tool used to manage packages in Debian-based systems, including Ubuntu. By using dpkg, we can see the version of a library installed on our system.

Before we proceed, let’s note that the dpkg command has more than one syntax we can use to check for the library version.

2.1. Using dpkg

First, there is the dpkg command with the -s option:

$ dpkg -s [library_name]

Here, we use the -s option to instruct dpkg to display details about the library.

So, let’s use the above syntax to check for the version of the libc6 library:

$ dpkg -s libc6
Package: libc6
Status: install ok installed
Version: 2.35-0ubuntu3.1
Original-Vcs-Browser: https://salsa.debian.org/glibc-team/glibc
Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git

In the example above, we see detailed information about the libc6 library including its version number. What’s more, we can see the installed version of the libc6 library is 2.35-0ubuntu3.1.

2.2. Using dpkg With grep

Next, we’ll use the dpkg command with its -l option in collaboration with the grep command:

$ dpkg -l | grep [ library_name ]

Here, -l instructs dpkg to list a comprehensive summary of the library. Also, we use the grep command to search for the library_name in our summary output.

So, let’s use the syntax above to check for the version of the libc6 library installed on our system:

$ dpkg -l | grep libc6
ii  libc6:amd64      2.35-0ubuntu3.1     amd64       GNU C Library: Shared libraries
ii  libc6-dbg:amd64  2.35-0ubuntu3.1     amd64       GNU C Library: detached debugging symbols

Using the command above, we display information about the libc6 library including the version number. To be specific, the version number of the libc6 library as displayed above is 2.35-0ubuntu3.1. However, this isn’t such a precise method.

2.3. Using dpkg-query

Finally, we can use the dpkg-query command to check for the version of a library. In fact, we use dpkg-query to get information about libraries listed in the dpkg database.

To be precise, we’ll use the dpkg-query command in collaboration with the -W option to display information about a library:

$ dpkg-query -W libc6
libc6:amd64	2.35-0ubuntu3.1

As we can see from the output above, we passed the libc6 library name and got the same version number as before.

3. Using the apt Command

The apt command is a high-level package management tool used to manage regular and library packages on Debian-based Linux systems. In this section, we’ll use it to check for the version of a library installed on our system from its package.

We use the apt command with the show option:

$ apt show [library_name]

Here, we include the show option to instruct apt to display details about a library.

So, let’s provide libc6 as the library name:

$ apt show libc6
Package: libc6
Version: 2.35-0ubuntu3.1
Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git
Download-Size: 3,235 kB

From the above output, we can see the version number, 2.35-Oubuntu3.1, of the installed libc6 library along with some additional information.

Other than checking the version of a library, we can also use the apt command to update a library to its latest version. For this, we first run the sudo apt update command followed by the sudo apt upgrade command with the name of the library we’d like to update:

$ sudo apt upgrade libc6

Using the above commands, we’re able to upgrade the libc6 library to its latest version.

4. Conclusion

In this article, we discussed how to check the version of a library in Linux using the dpkg and apt commands.

Additionally, we looked at some of the options these commands provide. Also, we briefly saw how we can use the apt command to ensure that a library is up-to-date. Consequently, this knowledge is important as it helps ensure that library-dependent applications function as expected.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.