Ubuntu

How to Find a Package that Provides a File on Ubuntu

Finding a package that provides a file is important on Linux systems including Ubuntu. The reason is it helps users solve package dependency problems that occur when you install a package on the system and if a file is missing, you won’t be able to perform the installation until the file is found. Further, it also helps users debug server-related issues on the system that may fail to start if a required library is missing.

If you want to find a package that provides a file on Ubuntu, you should follow this article’s guidelines.

Find a Package that Provides a File on Ubuntu

There are two ways to find a package that provides a file in Ubuntu and those are:

Method 1: apt-file

The first method to find a package that provides a file is by using an apt-file package. The apt-file marks the indexes for all installed packages which are present in the repository. By using apt-file, the users can search for a file provided by any of the packages present inside the repository, and this all searching process completes within a few seconds. This method is divided into two parts which are:

i: Installing apt-file

To install “apt-file” on your Ubuntu system, firstly update and upgrade the repository:

sudo apt update
sudo apt upgrade

 
Then install apt-file by using the below-mentioned command:

sudo apt install apt-file

 

The apt-file access database to find the packages belonging to a package and for that reason, it is important to update apt-file through the following command before searching for a file on Ubuntu:

sudo apt-file update

 

ii: Searching File Using apt-file

To search the file using apt-file, run the below-mentioned command along with the name of the file:

apt-file search <filename>

 
For example:

apt-file search hippo_opensim_viewer.xml

 

Or you can also use the file path to directly navigate the file, and its associated package:

apt-file search <file-path>

 
For example;

apt-file search /usr/share/bleachbit/cleaners/hippo_opensim_viewer.xml

 

Method 2: By Using dpkg

The other method to find a package that provides a file is by using the dpkg command, which is used to find the packages that were installed without a repository that is what makes it unique from apt-file. But dpkg can only list the files of packages which are installed in the system, whereas apt-file can even list the packages which are not installed in the system but are present in the repository.

Use the below-written dpkg file along with -S identifier for search, to find the package associated with the desired file:

dpkg -S <filename>

 
For example:

dpkg -S libsnapd-glib.so.1

 

Just like apt-file, you can also use a file path instead of just file name with the dpkg command to property navigate the file from its directory:

dpkg -S <path>

 
For example;

dpkg -S /usr/lib/x86_64-linux-gnu/libsnapd-glib.so.1

 

Bonus Tip

The dpkg command can also be used to search all the packages present inside a directory or library by using the below-mentioned command:

dpkg -S <Directory>

 
For instance, here I have displayed all the packages present inside the /var/lib:

dpkg -S /var/lib

 

Conclusion

To find a package that provides a file on Ubuntu, there are two ways: One is by using the “apt-file” tool which uses the database to search the file from the list of packages present inside the repository. The other method is by using the dpkg -S command to search the file from the list of installed packages. The apt-file tool needs to be installed, whereas “dpkg” is already present by default in Ubuntu.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.