Linux find package name

How do I find the package that provides a file?

Simple enough question: is there some shell command (or GUI method) I can use that, given the path to a file on my system, tells me what package put it there? Assuming the file did in fact come from a package, that is. Bonus question: what if it’s a file that isn’t installed on my system? Is there, say, a website that will let me look up a file and see what packages, if any, provide it?

I’ve always wondered this myself — I know with YUM you can do yum whatprovides / but I never really have found an alternative to that in Aptitude other than the Packages website

None of the answers here actually cover the Provides: mechanism. In some more detail, a command like mailx or sendmail is not included as a binary in any package; instead, various packages install their own binaries and then make some of them available under a «canonical» name via /etc/alternatives . See also askubuntu.com/questions/366135/…

10 Answers 10

You can use dpkg command to find out which installed package owns a file:

-S, --search filename-search-pattern. Search for a filename from installed packages.
$ dpkg -S /bin/ls coreutils: /bin/ls 

You can either search with a full path or with just the filename.

If you wish to search for files not yet installed on your computer, you can use the Ubuntu Packages Search, or apt-file as described in a different answer.

Hint: if you do not know the full path, but just the command name, use which to find he program: dpkg -S `which firefox`

@DanielTChen, but dlocate may not do the job, if dlocate’s database is out of date. You have to call sudo update-dlocatedb to update it.

If dpkg the exact path doesn’t return anything (e.g. dpkg /usr/bin/java ), try just the executable’s name (e.g. dpkg java ).

The apt-file command can do this for you from the command line. I use it frequently when building packages from source. For files provided by packages that are already installed on your system, apt-cache is another choice.

sudo apt-get install apt-file 

Then, you need to update it’s database:

And, finally, search the file:

$ apt-file find kwallet.h kdelibs5-dev: /usr/include/kwallet.h libkf5wallet-dev: /usr/include/KF5/KWallet/kwallet.h 

However a much friendlier way is to use the Ubuntu Packages Search website. They have an option to «search the contents of packages» for a specific filename.

In my opinion this should be the accepted answer. But in response to Ubuntu Packages Search, I might argue that a shell program this simple is extremely friendly and easy to remember (once you know it). If you use dpkg, apt-get, or aptitude as your standard tools, there is nothing friendly about firing up Chrome to surf the internet!

Читайте также:  Настройка сервера snmp linux

@user2097818 The reason this isn’t the accepted answer is that my primary question is restricted to files on the system and packages which are installed. apt-file often finds false positives, i.e. packages that aren’t installed. Of course this answer is great for the «bonus question».

For those from the Redhat side of the world — apt-file search <> is the closest analog to dnf/yum whatprovides <> .

I guess the question is why in the world is this functionality not built into apt , apt-get , or one of the other default apt-* programs. It seems like key piece of any package manager’s search capabilities.

A couple of caveats: 1) you have to install apt-file which is really annoying; 2) it is much slower than dpkg -S, eg on my system the latter takes less than half a second, whereas apt-file find takes 20 seconds! 3) most often, if you have a path on your system, then the package is installed, so why pay for the overhead of apt-file?

There’s also apt-file for looking up files in packages that aren’t installed. For example:

You can search the contents of packages included in the various Ubuntu releases on the Ubuntu Packages website. Look under the heading «Search the contents of packages».

For example, here are the search results for libnss3.so in focal (20.04):

You mean, which package and not which application. The application is your package manager, e.g. Software Center .

dpkg -S /usr/lib/tracker/tracker-store dpkg -S tracker-extract dpkg -S tracker-miner-fs 
% dpkg -S /usr/lib/tracker/tracker-store tracker: /usr/lib/tracker/tracker-store 
apt-file search /usr/lib/tracker/tracker-store 
apt-file search --regex /tracker-extract$ apt-file search --regex /tracker-miner-fs$ 
% apt-file search /usr/lib/tracker/tracker-store tracker: /usr/lib/tracker/tracker-store 

Or online here, in the section Search the contents of packages .

enter image description here

enter image description here

You mean, which package and not which application. The application is your package manager, e.g. Software Center. Okay. Thank you! 🙂

Thank you for all the help! None of these suggestions helped me find which package installed this/these applications though. All searches just lead back to «Tracker». I suspected it was Enthoughts’ Canopy though. That mile long EULA reminded me of my old Microsoft Windows daze, with which, I am so glad I am no longer involved. I saw that Tracker was installed yesterday so, as root, I got rid of it, along with Enthoughts’ Canopy and, all problems are solved. I really thank you for all your help. It is such a great thing to have such support. Thanks again! Kevin

This is an extension to Alexx Roche’s excellent answer. I tried to make an edit to that answer, but it got rejected (though not by Alexx)

I was trying to track down what installed which on my system. After a little work I created /usr/local/bin/apt-whatprovides

#!/bin/sh #apt-whatprovides ver. 201801010101 Copyright alexx, MIT Licence #rdfa:deps="[realpath,apt-file,grep,which,sh,echo]" BINARY="$(realpath $(which $@) 2>/dev/null)" [ -z "$BINARY" ] && BINARY="$@" echo Searching for $BINARY PACKAGE="$(apt-file search $BINARY|grep -E ":.*[^-.a-zA-Z0-9]$$")" echo "$" 

Though for most THINGs that are installed you can just use:

apt-file search $(realpath $(which THING)) | grep 'THING$' 

For THINGs that are not installed, you can use:

apt-file search THING | grep '/THING$' 

The apt-whatprovides script works for files that are and are not on your system. For example, my system lacked dig but had ping so this it what resulted:

pi@raspberrypi:~ $ apt-whatprovides ping Searching for /bin/ping inetutils-ping: /bin/ping iputils-ping: /bin/ping pi@raspberrypi:~ $ apt-whatprovides dig Searching for dig dnsutils: /usr/bin/dig epic4: /usr/share/epic4/script/dig epic4-help: /usr/share/epic4/help/8_Scripts/dig knot-dnsutils: /usr/bin/dig 

Источник

Читайте также:  Linux adobe reader ubuntu

Using ‘apt search’ and ‘apt show’ Commands to Search and Find Details of Packages in Ubuntu

This is a detailed beginners guide to apt search command. Using apt search and apt show commands, you can get details of the available versions, dependencies, repositories and other important information about packages in Ubuntu.

Have you ever wondered if a certain package is available to install via apt package manager?

Have you wondered if the package offered by Ubuntu repositories are the latest one or not?

The apt package manager in Ubuntu and many other distribution provides two handy apt command options for this purpose.

The apt search command looks for the provided string in the name and description of the packages.

The apt show command provides detailed information on a package:

The commands don’t require you to be root in Ubuntu. Here’s an example of these commands:

Apt Search and Apt Show Commands Example

Why would you want to use apt search or apt show command?

Let’s say you want to install Gambas programming language in Ubuntu. You are happy with your knowledge of the apt command so you decided to use the command line for installing application.

You open a terminal and use the apt command to install gambas but it results in unable to locate package error.

sudo apt install gambas Reading package lists. Done Building dependency tree Reading state information. Done E: Unable to locate package gambas

Why did Ubuntu not find the gambas package? Because there is no such package called gambas. Instead, it is available as gambas3. This is a situation where you could take the advantage of the apt search command.

Let’s move to apt show command. This command provides detailed information about a package, its repository, dependencies and a lot more.

Knowing what version of a package is available from the official repository could help you in deciding whether you should install it from some other sources.

The apt package manager works on a local database/cache of available packages from various repositories. This database contains the information about the available package version, dependencies etc. It doesn’t contain the entire package itself. The packages are downloaded from the remote repositories.

When you run the sudo apt update command, this cache is created/updated in the /var/lib/apt/lists/ directory. The apt search and apt show commands utilize this cache.

The term package is used for an application, program, software.

Apt Search Command

Let me continue the gambas example. Say, you search for

It will give you a huge list of packages that have “gambas” in its name or description. This output list is in alphabetical order.

Now, you’ll of course have to make some intelligent prediction about the package you want. In this example, the first result says “Complete visual development environment for Gambas”. This gives you a good hint that this is the main package you are looking for.

Читайте также:  Linux show file creation time

Apt Search Command Example

Why so many packages associated with gambas? Because a number of these gambas packages are probably dependencies that will installed automatically if you install the gambas3 package. If you use the ‘apt show gambas3‘ command, it will show all the dependencies that will be installed with gambas3 package.

Some of these listed packages could be libraries that a developer may need in some special cases while developing her/his software.

Use apt search for package name only

By default, apt search command looks for the searched term in both the name of the package and its description.

You may narrow down the search by instructing the apt command to search for package names only.

apt search --names-only search_term

If you are following this as a tutorial, give it a try. Check the output with search term ‘transitional’ with and without –names-only option and you’ll see how the output changes.

apt search transitional apt search --names-only transitional

Bonus Tip: You can use ‘apt list –installed’ command to look for installed packages in Ubuntu.

Get detailed information on a package using apt show command

The output of the apt search commands a brief introduction of the packages. If you want more details, use the apt show command.

apt show exact_package_name

The apt show command works on the exact package name and it gives you a lot more information on the package. You get:

  • Version information
  • Repository information
  • Origin and maintainer of the package information
  • Where to file a bug
  • Download and installation size
  • Dependencies
  • Detailed description of the package
  • And a lot more

apt show command example

You need to give the exact package name otherwise the apt show won’t work. The good thing is that tab completion works apt show command.

As you can see in the previous image, you have plenty of information that you may found helpful.

The apt show command also works on installed packages. In that case, you can see which source the package was installed from. Was it a PPA or some third-party repository or universe or the main repository itself?

Personally, I use apt show a lot. This helps me know if the package version provided by Ubuntu is the latest or not. Pretty handy tool!

Conclusion

If you read my detailed guide on the difference between apt and apt-get commands, you would know that this ‘apt search’ command works similar to ‘apt-cache search‘. There is no such command as “apt-get search”.

The purpose of creating apt command is to give you one tool with only enough option to manage the packages in your Debian/Ubuntu system. The apt-get, apt-cache and other apt tools still exist, and they can be used in scripting for more complex scenarios.

I hope you found this introduction to apt search and apt show commands useful. I welcome your questions and suggestions on this topic.

If you liked it, please share it on various Linux forums and communities you frequent. That helps us a lot. Thank you.

Источник

Оцените статью
Adblock
detector