Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get list of rpm packages installed in the system

Tags:

perl

rpm

how to get list of all rpm packages installed on Linux using Perl. any help is appreciated.

like image 459
doubledecker Avatar asked Dec 17 '22 08:12

doubledecker


1 Answers

I guess you can always use the rpm command:

$ rpm --query --all  --qf "%-30{NAME} - %{VERSION}\n"

You can then use this in a wide variety of ways:

use autodie;
open my $RPM_FH, "-|", qq(rpm --query --all --qf "%-30{NAME} - %{VERSION}\n");
my @rpmLines = <$RPM_FH>;
close $RPM_FH;

Or:

 my @rpmLines = qx(rpm --query --all --qf "%-30{NAME} - %{VERSION}\n");

I've also found RPM::Database which would be a more Perlish way of doing things. This package ties the RPM database to a hash:

use RPM::Database;

tie %RPM, "RPM::Database" or die "$RPM::err";

for (sort keys %RPM)
{
    ...
}

I have never used it, so I'm not sure exactly how it would work. For example, I assume that the value of each hash entry is some sort of database object. For example, I would assume that it would be important to know the version number and the files in your RPM package, and there must be someway this information can be pulled, but I didn't see anything in RPM::Database or in RPM::HEader. Play around with it. You can use Data::Dumper to help explore the objects returned.

WARNING: Use Data::Dumper to help explore the information in the objects, and the classes. Don't use it to figure out how to pull the information directly from the objects. Use the correct methods and classes.

like image 105
David W. Avatar answered Jan 14 '23 18:01

David W.