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?

James
  • 113
  • 1
    see https://unix.stackexchange.com/questions/269617/linux-equivalent-to-powershells-one-to-many-remoting/269626#269626 – Rui F Ribeiro Apr 23 '18 at 19:49
  • See also https://unix.stackexchange.com/q/269133/22812 :) – Anthony Geoghegan Apr 24 '18 at 09:50
  • Thanks @RuiFRibeiro. Although my actual problem is not execute the command in all machines, it will help in some cases. – James Apr 24 '18 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 '18 at 17:14
  • With that link, I was subtly making the point that there are a multitude of different ways for a package to be installed on a Unix-like system. As a corollary to that, there are multiple ways of listing the installed packages. FWIW, I both upvoted and voted to "keep open" your question and actually had an answer typed in my text editor - but I was too late to submit it. – Anthony Geoghegan Apr 24 '18 at 19:41
  • Also, some close-voters had voted to close your question because it was too broad and I think the question would have had a much better chance of staying open if you had narrowed its focus, e.g., listed specifically the range of distributions installed on the remote machines (answers would have been better if the possible distros were limited to Red Hat and Debian-based) and provided more background information, e.g., is listing the packages a once-off task or something that would be carried out regularly, etc. – Anthony Geoghegan Apr 24 '18 at 19:42
  • 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 '18 at 12:57

2 Answers2

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.

DopeGhoti
  • 76,081
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.

Santosh
  • 41
  • 3