Software >> OS >> Unix >> Linux >> Package Managers >> rpm and yum >> RHEL >> How to use repoquery or rpm or yum or subscription-manager to manage software packages

rpm

list all installed packages rpm -qa
show information about specific package rpm -qi packagename
list specific package if it is installed rpm -q packagename
install a package with verbose output rpm -ivh package.rpm
uninstall current version  rpm -e packagename
list dependencies 

rpm -qRp package.rpm

rpm -qR packagename

Apply this in a script to scan all installed packages and print
packages that depend on a specific package

e.g. check which installed package depends on libssh2

dp=libssh2
for pkg in `rpm -qa | sort | uniq`
do
   if [ "-`rpm -qR $pkg | grep $dp`-" != "--" ]; then
      echo $pkg depends on $dp
   fi
done

libcurl-7.29.0-57.el7_8.1.x86_64 depends on libssh2
mc-4.8.7-11.el7.x86_64 depends on libssh2
qemu-img-1.5.3-173.el7_8.3.x86_64 depends on libssh2
qemu-kvm-1.5.3-173.el7_8.3.x86_64 depends on libssh2

 

list files in package

rpm -qlp package.rpm

rpm -ql packagename

Look for dependency on a package if it was removed
 

rpm -e --test packagename

-e     ==> remove

--test ==> test only

It will give a warning
list package that provides a file rpm -qf file-full-path

e.g.

rpm -qf /bin/python

python-2.7.5-88.el7.x86_64


alternatively.

rpm -q --whatprovides /usr/bin/python

python-2.7.5-88.el7.x86_64
TEST package installation or removal rpm -ivh  - - test  packagename 

rpm -ev --test packagename
install all rpms that depend on each other.
 

put all .rpm in one directory

rpm -ivh *.rpm

check last install date of a package rpm --last -q packagename

e.g.

rpm --last -q sendmail
list packages that requires a specific package
(i.e. depends on)

e.g.

[root@rhel7client1 ~]# rpm -q --whatrequires glibc

glibc-common-2.17-307.el7.1.x86_64
libstdc++-4.8.5-39.el7.x86_64
pam-1.1.8-23.el7.x86_64
glibc-headers-2.17-307.el7.1.x86_64
glibc-devel-2.17-307.el7.1.x86_64
lockdev-1.0.4-0.13.20111007git.el7.x86_64
postgresql-libs-9.2.24-4.el7_8.x86_64
ppp-2.4.5-34.el7_7.x86_64


Thus the reverse will show that ppp requires glibc :

[root@rhel7client1 ~]#  rpm -qR ppp | grep glibc
glibc >= 2.0.6
 

List packages that are found in a particular yum repository


yum repository-packages repo-name list


## For example we have a repo named remi-php3
## we want to list ALL the packages found in this repo

yum repository-packages remi-php73 list

 

Display query output in specific formats with format strings ## display possible query tags to use in the query format

[root@localhost]# rpm --querytags
ARCH
ARCHIVESIZE
BASENAMES
BUGURL
BUILDARCHS
BUILDHOST
BUILDTIME
C
CHANGELOGNAME
CHANGELOGTEXT
CHANGELOGTIME
CLASSDICT
COLLECTIONS
CONFLICTFLAGS
CONFLICTNAME
CONFLICTNEVRS
CONFLICTS
CONFLICTVERSION
COOKIE
DBINSTANCE
DEPENDSDICT
DESCRIPTION
DIRINDEXES
DIRNAMES
DISTRIBUTION
DISTTAG
DISTURL
DSAHEADER
E
ENHANCEFLAGS
ENHANCENAME
ENHANCES
ENHANCEVERSION
EPOCH
EPOCHNUM
EVR
EXCLUDEARCH
EXCLUDEOS
EXCLUSIVEARCH
EXCLUSIVEOS
FILECAPS
FILECLASS
FILECOLORS
FILECONTEXTS
FILEDEPENDSN
FILEDEPENDSX
FILEDEVICES
FILEDIGESTALGO
FILEDIGESTS
FILEFLAGS
FILEGROUPNAME
FILEINODES
FILELANGS
FILELINKTOS
FILEMD5S
FILEMODES
FILEMTIMES
FILENAMES
FILENLINKS
FILEPROVIDE
FILERDEVS
FILEREQUIRE
FILESIZES
FILESTATES
FILEUSERNAME
FILEVERIFYFLAGS
FSCONTEXTS
GIF
GROUP
HDRID
HEADERCOLOR
HEADERI18NTABLE
HEADERIMAGE
HEADERIMMUTABLE
HEADERREGIONS
HEADERSIGNATURES
ICON
INSTALLCOLOR
INSTALLTID
INSTALLTIME
INSTFILENAMES
INSTPREFIXES
LICENSE
LONGARCHIVESIZE
LONGFILESIZES
LONGSIGSIZE
LONGSIZE
N
NAME
NEVR
NEVRA
NOPATCH
NOSOURCE
NVR
NVRA
O
OBSOLETEFLAGS
OBSOLETENAME
OBSOLETENEVRS
OBSOLETES
OBSOLETEVERSION
OLDFILENAMES
OPTFLAGS
ORDERFLAGS
ORDERNAME
ORDERVERSION
ORIGBASENAMES
ORIGDIRINDEXES
ORIGDIRNAMES
ORIGFILENAMES
OS
P
PACKAGER
PATCH
PATCHESFLAGS
PATCHESNAME
PATCHESVERSION
PAYLOADCOMPRESSOR
PAYLOADFLAGS
PAYLOADFORMAT
PKGID
PLATFORM
POLICIES
POLICYFLAGS
POLICYNAMES
POLICYTYPES
POLICYTYPESINDEXES
POSTIN
POSTINFLAGS
POSTINPROG
POSTTRANS
POSTTRANSFLAGS
POSTTRANSPROG
POSTUN
POSTUNFLAGS
POSTUNPROG
PREFIXES
PREIN
PREINFLAGS
PREINPROG
PRETRANS
PRETRANSFLAGS
PRETRANSPROG
PREUN
PREUNFLAGS
PREUNPROG
PROVIDEFLAGS
PROVIDENAME
PROVIDENEVRS
PROVIDES
PROVIDEVERSION
PUBKEYS
R
RECOMMENDFLAGS
RECOMMENDNAME
RECOMMENDS
RECOMMENDVERSION
RECONTEXTS
RELEASE
REMOVETID
REQUIREFLAGS
REQUIRENAME
REQUIRENEVRS
REQUIRES
REQUIREVERSION
RPMVERSION
RSAHEADER
SHA1HEADER
SIGGPG
SIGMD5
SIGPGP
SIGSIZE
SIZE
SOURCE
SOURCEPACKAGE
SOURCEPKGID
SOURCERPM
SUGGESTFLAGS
SUGGESTNAME
SUGGESTS
SUGGESTVERSION
SUMMARY
SUPPLEMENTFLAGS
SUPPLEMENTNAME
SUPPLEMENTS
SUPPLEMENTVERSION
TRIGGERCONDS
TRIGGERFLAGS
TRIGGERINDEX
TRIGGERNAME
TRIGGERSCRIPTFLAGS
TRIGGERSCRIPTPROG
TRIGGERSCRIPTS
TRIGGERTYPE
TRIGGERVERSION
URL
V
VCS
VENDOR
VERBOSE
VERIFYSCRIPT
VERIFYSCRIPTFLAGS
VERIFYSCRIPTPROG
VERSION
XP

## display NAME, VERSION, INSTALLTIME

# rpm -qa --qf "%-20{NAME} %-12{VERSION} %-30{INSTALLTIME:day}\n" | head -5
dos2unix             6.0.3        Fri Oct 02 2020
cups-libs            1.6.3        Wed May 27 2020
ansible-tower-ui     3.7.3        Fri Oct 16 2020
libXinerama          1.1.3        Wed May 27 2020
memcached            1.4.15       Fri Mar 13 2020


How to verify packages
## To verify all packages

rpm -Va

## To verify specific package

rpm -Vp packagename


## What are the meaning of the attribute marker characters from rpm -V command

the 9 character attribute :-

S  file Size differes
M  Mode differs
5  digest (MD5 sum) differs
D  Device major/minor number mismatch
L  readLink path mismatch
U  User ownership differs
G  Group ownership differs
T  mTime differs
P  caPabilities differ

the 1 character marker :-

c  %config i.e. config file
d  %doc  i.e. documentation file
g  %ghost file (i.e. not part of package payload)
l  %license file
r  %readme file

 

yum

list installed packages yum list installed
show information about a package yum info packagename
list repositories yum repolist
search package by name yum search firefox
List all available packages in all enabled repository yum search all
install from repository yum install firefox
install without using repository yum --disablerepo=* localinstall /var/tmp/rhel6/*.rpm
create and use the RHEL install CD as yum repository

e.g. for RHEL 6.1

# mkdir /mnt/iso
# mount -t iso9660 /dev/sr0 /mnt/iso
# mkdir /etc/rpm-gpg
# cp /mnt/iso/RPM-GPG-KEY-redhat-release /etc
# vi /etc/yum.repos.d/dvd.repo


dvd.repo

[rhel6.1-local]
name=RHEL 6.1 local repository
baseurl=file:///mnt/iso/
gpgcheck=1
gpgkey=file:///etc/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled=1

list the repo

# yum repolist

search package from the repo

# yum search packagename

install from the repo

# yum install packagename

list patch numbers of available advisories RHSA-xxxx:yyyy
- all categories (security, bug fix, enhancements)
yum updateinfo list available
list patch numbers of available advisories RHSA-xxxx:yyyy
- that are classified as security fix

 

yum updateinfo list available --security

list patch numbers of installed advisories RHSA-xxxx:yyyy
- all categories (security, bug fix, enhancements)
yum updateinfo list installed
list patch numbers of installed advisories RHSA-xxxx:yyyy
- that are classified as security fix
yum updateinfo list installed --security
Install a specific kernel version (or any package version) that is available in your repository but not installed by yum update ##

yum upgrade-to package-version

## e.g.

yum ugrade-to kernel-2.6.32-754.29.1.el6.x86_64

 

yumdownloader

 

   
Download a package's rpm to the current working directory

yumdownloader packagename
Download a package's rpm to a specific directory
yumdownloader packagename --destdir your-dest-directory

or

yumdownloader packagename --destdir=your-dest-directory

Download a package's rpm and it's dependent/required rpms
yumdownloader packagename --resolve


repoquery

List contents of a package

eg. to list contents of package named NetworkManager

repoquery --list NetworkManager

e.g. list contents of package named cifs-utils

# repoquery --list cifs-utils
/etc/cifs-utils/idmap-plugin
/etc/request-key.d/cifs.idmap.conf
/etc/request-key.d/cifs.spnego.conf
/usr/bin/cifscreds
/usr/bin/getcifsacl
/usr/bin/setcifsacl
/usr/lib64/cifs-utils/idmapwb.so
/usr/sbin/cifs.idmap
/usr/sbin/cifs.upcall
/usr/sbin/mount.cifs
/usr/share/man/man1/cifscreds.1.gz
/usr/share/man/man1/getcifsacl.1.gz
/usr/share/man/man1/setcifsacl.1.gz
/usr/share/man/man8/cifs.idmap.8.gz
/usr/share/man/man8/cifs.upcall.8.gz
/usr/share/man/man8/idmapwb.8.gz
/usr/share/man/man8/mount.cifs.8.gz

Show the location or URL where the rpm is downloaded from

e.g. to show the location of the rpm for that package

repoquery --location NetworkManager

 

subscription-manager


register with Red Hat

## Clean up any previous subscription

subscription-manager clean


## Register

subscription-manager register
username: your_username
password: your_password


## Attach

subscription-manager attach

list repositories ## List all

subscription-manager repos --list


## List enabled

subscription-manager repos --list-enabled
select repositories to enable/disable
## Disable all

subscription-manager repos --disable=*


## Enable all

subscription-manager repos --enable=*


## Disable all and enable some

subscription-manager repos --disable=* --enable=repo_name_1 --enable=repo_name_2


## wildcards supported in repo_name
List releases available for the current machine subscription-manager release --list
Set your desired release ## e.g. set to latest release for RHEL 7

subscription-manager release --set=7Server

## e.g. set to release 7.8

subscription-manager release --set=7.8