Score:5

How to find the installation method for a given command?

lu flag

I usually install packages using the following methods:

  • From Ubuntu repositories: sudo apt install commandName
  • From a PPA: I have to add the PPA than run: sudo apt install commandName
  • Directly from a deb file, (e.g downloaded from github, such as pandoc): sudo apt install /path/to/packageName
  • Using Snap.
  • Using AppImages
  • Using flatpak

Sometimes, I need that information, i.e. which method I have used to install a given command/package.

Is there a command in Ubuntu, given a command name, it will return that information?

guiverc avatar
cn flag
I usually use `whereis` to find it's location. That detail alone can tell you the type of package in many cases & that outpu will decide if I need to go further.. ie. I might `dpkg -S` if the first result pointed to a *deb* installed etc.. but I'll also know my release details which influence how I interpret results. eg. `whereis ls` gives me detail for the `dpkg -S`, but for my release `whereis chromium` tells me it's a *snap* so I have no need for any further searching...
hr flag
If a command is provided by a deb package (either directly, or from a PPA, or from an official repository), then `apt policy <packagename>` might be useful for determining which
OK-Validation avatar
lu flag
@steeldriver: Thank you! that's a useful command.
Score:5
cn flag

Is there a command in Ubuntu, given a command name, it will return that information?

No, there isn' t. You need to do some investigations. First, the type command will reveal information about the nature of the command:

type <command>

This command will indicate whether it is a shell built-in, an alias, and if an executable, whether it is hashed, i.e. indexed for speedy retrieval –this indicates you have run the command at least once before in the session–, or where the binary is located.

The place where the executable is installed already hints towards how a package was installed. The command which reveals its location:

which <command>
  • Executables of packages installed using the regular APT system, i.e., from the Ubuntu software repositories, from a PPA you added or from a downloaded .deb installation file, will typically be installed in /usr/bin or /bin. Use the command dpkg -S filename-search-pattern to find out which package has installed the file (source).
  • Executables installed by Snap are exposed in a dedicated directory that is added to the PATH, i.e. /snap/bin. Confirm that this is a snap package by finding it in the output of snap list.
  • No executable are exposed in the PATH by Flatpak. You can, however, tell whether a package is installed that way from the output of flatpak list --app.
  • Executable AppImages can be placed anywhere. There is thus no general method to recognized their source. Typically, however, they will not have been renamed and then can be easily recognized by their extension .AppImage.

In case your package was installed as a .deb, you can further differentiate looking at the output of:

apt policy <package>

An URL in the output will directly hint from which source the package came if it was installed from a software source. The absence of an URL indicates the package was installed from a locally downloaded .deb.

OK-Validation avatar
lu flag
Probably this is a good indicator that a script is needed to find that information.
hr flag
You might also mention `type <command>` as an alternative to `which <command>` since it will resolve the cases of shell builtins / functions / aliases. As well, `realpath -f $(which command)` is sometimes helpful where commands are symlinked (those managed by the `update-alternatives` mechanism for example).
OK-Validation avatar
lu flag
@steeldriver: Exaclty. ironically I was reading about that thanks to a comment to my question here: https://unix.stackexchange.com/q/683661/504663
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.