5

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?

  • 2
    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... – guiverc Dec 24 '21 at 05:19
  • 1
    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 – steeldriver Dec 24 '21 at 13:01
  • @steeldriver: Thank you! that's a useful command. – Amazigh_05 Dec 24 '21 at 15:14

1 Answers1

5

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.

vanadium
  • 88,010
  • Probably this is a good indicator that a script is needed to find that information. – Amazigh_05 Dec 24 '21 at 15:19
  • 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). – steeldriver Dec 24 '21 at 15:25
  • @steeldriver: Exaclty. ironically I was reading about that thanks to a comment to my question here: https://unix.stackexchange.com/q/683661/504663 – Amazigh_05 Dec 24 '21 at 15:28