RPM (Red Hat Package Manager) is primarily used for package management in Red Hat-based operating systems like RHEL, CentOS, and Fedora. However, tools like rpm
can also be used on Debian-based systems if needed. Similarly, dpkg
(Debian Package) can sometimes be used on Red Hat systems. This cross-usage is typically done to access specific functionalities available in one package manager but not the other.
You can check your operating system details using the following commands:
cat /etc/os-release
cat /etc/system-release
cat /etc/redhat-release
uname -a
uname -a
prints all available information about the system.-
uname
alone prints the kernel name. -
-a
(all) prints all system information.Linux localhost.localdomain 5.14.0-522.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Oct 20 13:04:34 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
- Linux: Kernel name indicating the system is running Linux.
- localhost.localdomain: Hostname of the system.
- 5.14.0-522.el9.x86_64: Kernel version, including:
- 5.14.0: Major and minor version numbers.
- 522: Patch level (release number).
- el9: Indicates Red Hat Enterprise Linux 9 (RHEL 9) distribution.
- x86_64: Architecture (64-bit x86).
- #1 SMP PREEMPT_DYNAMIC: Additional kernel build information:
- #1: Build number.
- SMP: Symmetric Multi-Processing support.
- PREEMPT_DYNAMIC: Dynamic preemption model.
- Sun Oct 20 13:04:34 UTC 2024: Build date and time of the kernel.
- x86_64 x86_64 x86_64: System architecture (64-bit x86).
- GNU/Linux: Indicates a GNU/Linux operating system.
-
Run the following commands to check which package manager is available on your system:
rpm
dnf
yum
dpkg
apt
- If it's an RPM-based system, commands like
rpm
,dnf
, andyum
will provide outputs. - In Debian-based systems,
dpkg
andapt
will be available.
The RPM database is stored in /var/lib/rpm
. List its contents using:
# ls /var/lib/rpm
Output:
/var/lib/rpmdb.sqlite
/var/lib/rpmdb.sqlite-shm
/var/lib/rpmdb.sqlite-wal
-
rpmdb.sqlite (Main RPM Database)
- Contains all package metadata:
- Installed packages
- Package versions
- Dependencies
- File locations
- Configuration files
- Queried when you run
rpm -qa
(query all packages).
- Contains all package metadata:
-
rpmdb.sqlite-shm (Shared Memory File)
- Acts as temporary shared memory for SQLite transactions.
- Improves read/write performance by caching queries.
- Created dynamically and may not always be present.
-
rpmdb.sqlite-wal (Write-Ahead Log)
- Temporarily stores uncommitted changes before writing to
rpmdb.sqlite
. - Ensures data consistency in case of a crash.
- Cleared when changes are committed.
- Temporarily stores uncommitted changes before writing to
- Installing a Package: When you run
rpm -i package.rpm
, RPM writes package details torpmdb.sqlite
, with temporary changes stored inrpmdb.sqlite-wal
. - Querying Packages: When you run
rpm -qa
, RPM readsrpmdb.sqlite
and may userpmdb.sqlite-shm
to speed up queries. - Committing Changes: When a transaction is committed,
rpmdb.sqlite-wal
is merged intorpmdb.sqlite
, andrpmdb.sqlite-wal
is cleared.
# rpm --version
Output:
RPM version 4.16.1.3
# rpm --help
Syntax:
# rpm -q package_name
-q
: Query mode.
Examples:
# rpm -q python3
-
If installed, output:
python3-3.9.7-2.el9.x86_64
-
If not installed, output:
package python3 is not installed
Other examples:
rpm -q rpm
rpm -q firefox
rpm -q vsftpd
rpm -qa package-name
-
-qa
: Query all installed packages. -
To count total number of packages:
rpm -qa | wc -l
rpm -qa --last
-
--last
: List packages by install time, most recent first. -
To see the 10 most recently installed packages:
rpm -qa --last | head
rpm -qa | grep package_name
Examples:
rpm -qa | grep vim
rpm -qa | grep google
rpm -qi package_name
-qi
: Query information about a package.
Examples:
rpm -qi openssh-server
rpm -qi rpm
rpm -qi passwd
rpm -ql package_name
-ql
: Query list of files installed by the package.
Examples:
rpm -ql openssh-server
rpm -ql nano
rpm -qc package_name
-qc
: Query configuration files.
Example:
rpm -qc openssh-server
rpm -qd package_name
-qd
: Query documentation files.
Example:
rpm -qd openssh-server
rpm -qR package_name
-qR
: Query requirements (dependencies).
Examples:
rpm -qR openssh-server
rpm -qR yum
rpm -q --provides package_name
--provides
: List capabilities provided by the package.
Examples:
rpm -q --provides openssh-server
rpm -q --provides vim-common
rpm -q --dump package_name
--dump
: Dump basic file information.
Examples:
rpm -q --dump nano
rpm -q --dump openssh-server
rpm -qs package_name
-qs
: Query states of files installed by the package.
Examples:
rpm -qs nano
rpm -qs acl
rpm -qs openssh-server
rpm -qf /path/to/file
Examples:
rpm -qf /usr/bin/nano
rpm -qf /etc/yum.repos.d/centos.repo
rpm -qf /usr/bin/python
Use wget
to download a package:
wget https://nginx.org/packages/rhel/9/x86_64/RPMS/nginx-1.26.2-2.el9.ngx.x86_64.rpm
Before Downloading:
- Verify the package's release, version, and architecture match your system.
- Check package dependencies and ensure they are available.
- Verify that the package does not conflict with existing installed packages.
- Check the package signature to confirm authenticity.
- Review changelogs or documentation for important updates or known issues.
rpm -qp package_file.rpm
-qp
: Query package.
Example:
rpm -qp nginx-1.26.2-2.el9.ngx.x86_64.rpm
rpm -qip package_file.rpm
-qip
: Query information about the package file.
Example:
rpm -qip nginx-1.26.2-2.el9.ngx.x86_64.rpm
rpm -qcp package_file.rpm
-qcp
: Query configuration files from the package file.
Example:
rpm -qcp nginx-1.26.2-2.el9.ngx.x86_64.rpm
rpm -qlp package_file.rpm
-qlp
: Query list of files in the package file.
Example:
rpm -qlp nginx-1.26.2-2.el9.ngx.x86_64.rpm
rpm -qdp package_file.rpm
-qdp
: Query documentation files in the package file.
Example:
rpm -qdp nginx-1.26.2-2.el9.ngx.x86_64.rpm
rpm -qRp package_file.rpm
-qRp
: Query requirements (dependencies) of the package file.
Example:
rpm -qRp nginx-1.26.2-2.el9.ngx.x86_64.rpm
Since -qL
is not a standard option for license, use the following:
rpm -qip package_file.rpm | grep License
Example:
rpm -qip nginx-1.26.2-2.el9.ngx.x86_64.rpm | grep License
rpm -V package_name
-V
: Verify mode.- Checks size, permissions, checksum, timestamps, etc.
- No output means no changes detected.
- Outputs a status string if files are modified.
- S: File size differs.
- M: Mode (permissions) changed.
- 5: MD5 checksum mismatch.
- T: Timestamp changed.
- D: Device major/minor number mismatch.
- U: User ownership changed.
- G: Group ownership changed.
- L: Symbolic link path mismatch.
- P: Capabilities differ.
- c: Configuration file.
rpm -V openssh-server
Possible Output:
S.5....T. c /etc/ssh/sshd_config
missing c /etc/ssh/sshd_config
- Indicates that
/etc/ssh/sshd_config
has changes in size, MD5 checksum, and timestamp.
rpm -Vv package_name
-Vv
: Verbose verify.- Displays detailed information about the state of each file.
Example:
rpm -Vv passwd
rpm -Vv --nodeps package_name
--nodeps
: Ignore dependencies during verification.
Example:
rpm -Vv --nodeps passwd
Package selection refers to identifying and selecting a package for querying, verifying, or managing.
-
By Package Name:
rpm -q package_name
-
By File Path:
-
Find which package owns a file:
rpm -qf /path/to/file
-
Verify a file's integrity and ownership:
rpm -Vf /path/to/file
-
-
By External Commands:
-
Locate a command/file before querying:
which command
whereis command
-
Use the -i
option to install packages.
rpm -i package_file.rpm
-
If the package is downloaded locally:
rpm -i nginx-1.26.3-1.el9.ngx.x86_64.rpm
-
If installing directly from a URL:
rpm -i https://nginx.org/packages/rhel/9/x86_64/RPMS/nginx-1.26.3-1.el9.ngx.x86_64.rpm
rpm -i package_file.rpm
- Note: If there are no dependencies, the package will install successfully.
Example:
rpm -i httpd-2.4.62-4.el9.x86_64.rpm
- If dependencies are missing, you will receive errors indicating which dependencies are required.
Install necessary dependencies one by one:
rpm -i dependency1.rpm
rpm -i dependency2.rpm
rpm -i package_file.rpm
rpm -i --nodeps package_file.rpm
- Warning: Skipping dependencies may result in a non-functional package.
rpm -ivh package_file.rpm
-i
: Install.-v
: Verbose output.-h
: Display hash marks to show progress.
Use the -U
option to upgrade a package.
rpm -U package_file.rpm
- Upgrades an existing package or installs it if it's not already installed.
- Replaces older versions with newer ones.
- Preserves configuration files to avoid overwriting custom settings.
Example:
rpm -U nginx-1.26.3-1.el9.ngx.x86_64.rpm
Use the -e
option to uninstall a package.
rpm -e package_name
- Checks for dependencies; will fail if other packages depend on it unless
--nodeps
is used. - Removes installed files, except modified configuration files in
/etc/
. - Updates the RPM database to reflect the removal.
Example:
rpm -e httpd-filesystem
rpm -evh package_name
-e
: Erase (uninstall).-v
: Verbose output.-h
: Display hash marks to show progress.
rpm -e --nodeps package_name
- Warning: This may break other packages that depend on the removed package.
- Recursive Dependencies: When installing packages with multiple dependencies, you may need to install several packages to resolve all requirements.
- Using
--nodeps
: Skipping dependency checks is generally discouraged as it can lead to broken packages or system instability. - Configuration Files: Uninstallation typically doesn't remove configuration files in
/etc/
to preserve user settings. These may need to be removed manually if desired. - Regular Verification: It's good practice to verify package integrity periodically to detect unauthorized changes or corruption.