0

I'm looking for some standard way to get all installed packages in my Linux machines, but I'd like to achieve it independently of the distro.

I found some very good answers here for some specific distros like Debian/Ubuntu, Fedora/CentOS, etc., but I had no success in a distro-independent way to get this info.

My first option was: List all directories in some specific places like /opt or /usr/bin.  But using this approach, I don't have the information about the version installed.  In the best case, I can get the names of installed packages and just that.

Some background:

I have a list of IP addresses and ports (in a spreadsheet) and need to SSH into each system and get the installed packages and their versions, but the distros may vary a lot.

It will be a one-time task, but other spreadsheets will come in the future, so I will use the same solution more than one time.

As I know some of the machines in the spreadsheet and based on the clients’ information, I can infer that the list are for servers, with just a few desktops. As I said before, the distros may vary a lot, but it’s safe to say that I have a great number of Ubuntu, Debian and CentOS machines.

For desktops, most are Ubuntu with some macOS.

I can use some Bash, Python or PHP script if that helps.

For the first version, I decided to ignore language-specific package managers such as npm,rvm, composer, etc, even if the packages were installed globally.

In short: Is there any standard way to get all installed packages independent of the distro?

7
  • 1
  • See also unix.stackexchange.com/q/269133/22812 :) Apr 24, 2018 at 9:50
  • Thanks @RuiFRibeiro. Although my actual problem is not execute the command in all machines, it will help in some cases.
    – James
    Apr 24, 2018 at 16:41
  • @AnthonyGeoghegan. Install packages is not in my plans for this problem, since I just need to list them. Thank for the tip anyway.
    – James
    Apr 24, 2018 at 17:14
  • 1
    I didn't get your intention in the first comment @AnthonyGeoghegan. I got your point now and thank you for the tips to improve the question. Independently of the accepted answer, I'll try to edit the question to improve it and, maybe, help other ones with similar problems.
    – James
    Apr 25, 2018 at 12:57

2 Answers 2

1

Not completely, as some distributions to this day use tar as their "package manager". However you can usually look at /etc/issue to get the name of the distribution and release of a system in question, and make some inferences. Alternatively, you can simply check for the presence of binaries like yum, up2date, apt, emerge, pacman, brew, port, choco, et cetera. However, this may fail interestingly on (say) a Debian-derived system whereupon someone decided to try and get yum working.

3
  • 1
  • I don't agree that this question is opinion-based but I'll accept the close votes and accept this answer as correct. I'll go with this approach of searching for the binaries of package managers, because it looks like a good option to solve my problem.
    – James
    Apr 24, 2018 at 17:11
  • 1
    I agree that this question isn't really looking for opinion per se, but more is asking for something that is hard to deliver.
    – DopeGhoti
    Apr 24, 2018 at 19:38
1

You can definitely, develop an ansible playbook which will check the operating system of the machine/server/host and then use respective package manager command to list the package names.

1
  • Are you talking about it? I didn't know it, but I'll give it a try.
    – James
    Apr 25, 2018 at 21:13

Not the answer you're looking for? Browse other questions tagged .