In this tutorial, we will show you how to install RPM Packages on CentOS. In the world of Linux, particularly in CentOS environments, RPM packages serve as the fundamental building blocks for software installation and management. Whether you’re a system administrator managing multiple servers or a Linux enthusiast exploring CentOS for personal projects, understanding how to properly install and manage RPM packages is essential for maintaining a stable, secure, and functional system. This comprehensive guide will walk you through everything you need to know about working with RPM packages on CentOS, from basic installation methods to advanced management techniques.
Understanding RPM Packages
RPM (Red Hat Package Manager) is both a package format and the package management system used by CentOS, Red Hat Enterprise Linux (RHEL), Fedora, and other similar distributions. It was designed to simplify the process of distributing, installing, and managing software on Linux systems.
Structure and Components of RPM Packages
An RPM package is essentially an archive file with the .rpm
extension that contains:
- The software files to be installed
- Metadata about the package (name, version, architecture, etc.)
- Scripts that run before, during, or after installation
- Dependency information listing other packages required for proper functioning
The naming convention for RPM packages typically follows this pattern: name-version-release.architecture.rpm
. For example, httpd-2.4.37-43.el8.x86_64.rpm
indicates the Apache HTTP server, version 2.4.37, release 43, built for Enterprise Linux 8, for 64-bit x86 architecture.
Types of Software Available as RPM Packages
Nearly every type of software for CentOS is available in RPM format, including:
- System utilities and commands
- Server applications (web servers, database servers)
- Desktop applications
- Development tools and libraries
- Kernel modules and drivers
Sources for Obtaining RPM Packages
You can obtain RPM packages from several reliable sources:
- Official CentOS repositories
- Third-party repositories like EPEL (Extra Packages for Enterprise Linux)
- Software vendor websites
- Community repositories
- Self-compiled RPMs from source code
Prerequisites for Installing RPM Packages
Before diving into installation methods, ensure you have the right environment and permissions to work with RPM packages.
System Requirements
- A running CentOS system (this guide applies to CentOS 7, 8, and Stream)
- Sufficient disk space for the package and its dependencies
- Compatible system architecture (x86_64, aarch64, etc.)
- Internet connection (for repository-based installations)
Required User Permissions
Installing packages system-wide requires elevated privileges:
# Using sudo for individual commands
sudo rpm -i package.rpm
# Or switching to root user
su -
rpm -i package.rpm
Safely Downloading RPM Packages
When downloading packages outside official repositories:
- Always verify the source website’s authenticity
- Use HTTPS connections when available
- Compare checksums or GPG signatures before installation
- Scan downloads for malware if obtaining from untrusted sources
Verifying Package Authenticity
To check a package’s GPG signature:
rpm --checksig package.rpm
If you’ve imported the appropriate GPG keys, you should see output indicating the package is properly signed.
Method 1: Installing RPM Packages with the rpm Command
The rpm
command is the foundational tool for working with RPM packages. It provides direct control over package operations but requires manual dependency management.
Basic Syntax and Common Flags
The basic syntax for installing a package with rpm is:
rpm -i package.rpm
Common flags include:
-i
: Install a package-v
: Verbose mode (shows detailed output)-h
: Print hash marks during installation to show progress--test
: Test run without actually installing-U
: Upgrade a package (install if not present, upgrade if installed)-F
: Freshen a package (only upgrade if already installed)
A typical installation command combines these flags:
rpm -ivh package.rpm
Step-by-Step Installation Process
- Download the RPM package to your system:
wget https://example.com/path/to/package.rpm
- Check for dependencies before installation:
rpm -qpR package.rpm
- Install the package:
sudo rpm -ivh package.rpm
- Verify the installation:
rpm -q package-name
Limitations of Using rpm Directly
The main limitation of the rpm
command is that it doesn’t automatically resolve dependencies. If a package requires other packages, you’ll see errors like:
error: Failed dependencies:
libexample.so.1()(64bit) is needed by package-1.0-1.el8.x86_64
other-package >= 2.0 is needed by package-1.0-1.el8.x86_64
You would then need to manually install each dependency before retrying.
Real-World Example: Installing a Local RPM
Let’s install the htop monitoring tool from a local RPM file:
# Download the package
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/h/htop-2.2.0-3.el7.x86_64.rpm
# Check dependencies
rpm -qpR htop-2.2.0-3.el7.x86_64.rpm
# Install the package
sudo rpm -ivh htop-2.2.0-3.el7.x86_64.rpm
# Verify installation
which htop
htop --version
Method 2: Installing RPM Packages with the yum Command
While rpm
provides low-level package management, yum
(Yellowdog Updater, Modified) offers a higher-level interface with automatic dependency resolution.
Basic Syntax and Benefits
The basic syntax for installing an RPM package with yum is:
sudo yum localinstall package.rpm
Or for a package from repositories:
sudo yum install package-name
Benefits of using yum include:
- Automatic dependency resolution and installation
- Access to configured repositories
- Transaction history and rollback capabilities
- Package group management
How yum Handles Dependencies
When installing a package, yum:
- Analyzes the package’s dependencies
- Checks installed packages to see what’s missing
- Searches configured repositories for the needed dependencies
- Creates a transaction set including all required packages
- Prompts for confirmation before proceeding
- Downloads and installs everything in the correct order
Step-by-Step Installation with Examples
To install an RPM file from your local system:
# Install a local RPM file
sudo yum localinstall ./package.rpm
# Alternative syntax (CentOS 7 and later)
sudo yum install ./package.rpm
To install from repositories:
# Install a specific package
sudo yum install httpd
# Install multiple packages
sudo yum install httpd php mysql
Other Useful yum Commands
# Search for a package
yum search keyword
# Get information about a package
yum info package-name
# List available package groups
yum group list
# Install a package group
sudo yum group install "Development Tools"
# Download a package without installing
yumdownloader package-name
Real-World Example: Installing and Configuring NGINX
# Install NGINX
sudo yum install nginx
# Start and enable NGINX
sudo systemctl start nginx
sudo systemctl enable nginx
# Check status
sudo systemctl status nginx
# Open firewall ports if needed
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Method 3: Installing RPM Packages with the dnf Command
DNF (Dandified YUM) is the next-generation package manager that replaced yum in newer CentOS versions, especially CentOS 8 and Stream.
Introduction to dnf and When to Use It
DNF provides improved dependency resolution, better performance, and more consistent behavior compared to yum. Use dnf on:
- CentOS 8 and later
- CentOS Stream
- RHEL 8 and later
- Fedora (all recent versions)
Basic Syntax and Differences from yum
The syntax is very similar to yum:
# Install from repositories
sudo dnf install package-name
# Install local RPM
sudo dnf install ./package.rpm
Key differences include:
- Improved dependency resolution algorithm
- Better performance through optimized metadata handling
- Modular design with plugin support
- More consistent command-line options
Step-by-Step Installation with Examples
# Update DNF package cache
sudo dnf makecache
# Install a package
sudo dnf install httpd
# Install with confirmation disabled
sudo dnf -y install httpd
# Install a specific version
sudo dnf install httpd-2.4.37
Advantages of dnf Over Older Package Managers
- Better memory management
- Improved transaction history tracking
- Support for weak dependencies
- Better handling of package replacements
- Modular content support
- Clearer error messages
Real-World Example: Installing Development Tools
# Install the Development Tools group
sudo dnf group install "Development Tools"
# Check what was installed
rpm -qa | grep -E 'gcc|make|gdb|git'
# Install additional development libraries
sudo dnf install cmake cmake-gui
Verifying Installed RPM Packages
After installation, it’s important to verify that packages installed correctly and are functioning as expected.
Methods to Confirm Successful Installation
- Check if the package is listed as installed:
rpm -q package-name
- Verify the package version:
rpm -q package-name --qf "%{VERSION}\n"
- Check the full package information:
rpm -qi package-name
- List files installed by the package:
rpm -ql package-name
- Verify package file integrity:
rpm -V package-name
Understanding Verification Output
When using rpm -V
, output indicates changes since installation:
.
(dot): Test passedS
: File size differsM
: Mode differs (includes permissions and file type)5
: MD5 sum differsD
: Device major/minor number mismatchL
: Symbolic link path mismatchU
: User ownership differsG
: Group ownership differsT
: Modification time differs
Checking for Broken Dependencies
To find packages with broken dependencies:
rpm -Va
Or using yum/dnf:
# Using yum
yum verify
# Using dnf
dnf check
Managing RPM Packages
Proper package management goes beyond installation to include updates, queries, and removal when necessary.
Updating Installed Packages
Using yum:
# Update a specific package
sudo yum update package-name
# Update all packages
sudo yum update
Using dnf:
# Update a specific package
sudo dnf update package-name
# Update all packages
sudo dnf update
Using rpm (not recommended for updates):
sudo rpm -Uvh package.rpm
Listing and Finding Installed Packages
To list all installed packages:
# Using rpm
rpm -qa
# Sort alphabetically
rpm -qa | sort
# Using yum
yum list installed
# Using dnf
dnf list installed
To find specific packages:
# Search by partial name
rpm -qa | grep httpd
# Find which package owns a file
rpm -qf /usr/bin/htop
Removing/Uninstalling Packages
Using rpm:
sudo rpm -e package-name
Using yum:
sudo yum remove package-name
Using dnf:
sudo dnf remove package-name
Handling Package Conflicts
When encountering conflicts:
- Identify conflicting packages:
sudo yum check
- Consider using
--allowerasing
with dnf to resolve conflicts automatically:sudo dnf install package-name --allowerasing
- For rpm, you might need to use
--force
(use with caution):sudo rpm -ivh --force package.rpm
Creating Backups Before Major Changes
Before major system changes:
# List and save currently installed packages
rpm -qa > installed_packages.txt
# For a specific restore plan
yum install yum-utils
sudo yumdownloader $(rpm -qa)
Troubleshooting Common Issues
Even with the best package management practices, issues can arise. Here are solutions to common problems.
Dependency Errors and Resolution
When you see “Failed dependencies” errors:
- Identify the missing dependencies:
rpm -qpR package.rpm
- Install them manually or use yum/dnf:
sudo yum install dependency1 dependency2
- Then retry the original installation:
sudo yum localinstall package.rpm
Package Conflicts and Resolution Strategies
For package conflicts:
- Use more powerful dependency resolution:
sudo dnf install package-name --best --allowerasing
- Consider using a different package version:
sudo dnf install package-name-1.2.3
- In extreme cases, exclude conflicting packages:
sudo dnf install package-name --exclude=conflicting-package
Handling Version Compatibility Issues
When dealing with version incompatibilities:
- Check available versions:
yum --showduplicates list package-name
- Specify the desired version:
sudo yum install package-name-1.2.3
- Consider adding version-specific repositories
Dealing with Corrupted Packages
For corrupted packages:
- Clear the yum/dnf cache:
sudo yum clean all # or sudo dnf clean all
- Re-download the package:
yumdownloader package-name
- Verify the package integrity:
rpm --checksig package.rpm
Permission Problems
Common permission issues include:
- Not using sudo/root privileges (solution: prefix commands with sudo)
- SELinux blocking installations (check with
ausearch -m avc
) - Read-only filesystem (check mount options with
mount
)
GUI Methods for RPM Installation
For those who prefer graphical interfaces, CentOS offers several GUI-based methods for package management.
Using File Manager for RPM Installation
- Navigate to the downloaded RPM file in the file manager
- Right-click on the file
- Select “Open with Software Install”
- Follow the prompts to complete the installation
The Software Center Application
- Launch Software Center from the Applications menu
- Use the search function to find desired software
- Click “Install” next to the package name
- Enter your password when prompted
Other Graphical Package Management Tools
- PackageKit: A front-end for various package managers
- Yumex-DNF: Yum Extender, a graphical package manager
- GNOME Software: The default software manager in GNOME desktop
Advantages and Limitations of GUI Installation
Advantages:
- User-friendly interface
- Visual feedback on installation progress
- Easy browsing of available software
- Category-based organization
Limitations:
- Fewer advanced options compared to command-line tools
- May not show detailed error messages
- Limited batch processing capabilities
- Not available on minimal server installations
Best Practices for RPM Package Management
Adopting these best practices will help maintain system stability and security.
Creating a Consistent Package Management Workflow
Develop a routine approach:
- Regular system updates (weekly or monthly)
- Testing updates in non-production environments first
- Maintaining consistent package versions across similar systems
- Documenting custom package installations and configurations
Security Considerations
Enhance security by:
- Only installing packages from trusted sources
- Verifying package signatures before installation
- Keeping packages updated to patch security vulnerabilities
- Removing unnecessary packages to reduce attack surface
Using Repositories vs. Standalone RPM Packages
As a general rule:
- Prefer official repositories for system stability
- Use third-party repositories (like EPEL) for additional software
- Resort to standalone RPMs only when necessary
- Consider creating your own internal repository for custom packages
Regular System Updates and Maintenance
Establish a maintenance schedule:
# Update package metadata
sudo dnf makecache
# Check for available updates
sudo dnf check-update
# Apply security updates only
sudo dnf update --security
# Apply all updates
sudo dnf update
Testing Packages in Non-Production Environments
Before deploying to production:
- Install and test in development environments
- Use snapshot functionality if available (like in virtual environments)
- Create a test plan covering critical functionality
- Document any special considerations or configurations
Advanced RPM Package Operations
For power users and system administrators, RPM offers advanced capabilities beyond basic installation.
Extracting Content from RPM Packages Without Installation
To inspect package contents without installing:
# Create a directory for extraction
mkdir extract-dir
# Extract package contents
rpm2cpio package.rpm | cpio -idmv -D extract-dir
# Navigate to the extracted files
cd extract-dir
ls -la
Rebuilding and Modifying Packages
Basic package rebuilding:
# Install rpmbuild tools
sudo dnf install rpm-build rpmdevtools
# Set up build environment
rpmdev-setuptree
# Rebuild a source package
rpmbuild --rebuild package.src.rpm
# Rebuild with custom options
rpmbuild -ba --with custom_option package.spec
Creating Custom RPM Repositories
To create a local repository:
# Install createrepo
sudo dnf install createrepo
# Create repository structure
mkdir -p /var/www/html/my-repo
# Copy RPM files
cp *.rpm /var/www/html/my-repo/
# Generate repository metadata
createrepo /var/www/html/my-repo/
# Configure as a repository
cat > /etc/yum.repos.d/my-repo.repo << EOF
[my-repo]
name=My Custom Repository
baseurl=file:///var/www/html/my-repo
enabled=1
gpgcheck=0
EOF
Querying Package Information from Repositories
# List all available packages in a repository
dnf repository-packages repo-name list available
# Get info about a package without installing
dnf info package-name
# List package dependencies
dnf repoquery --requires package-name
# Find which package provides a specific file
dnf provides /path/to/file
Using RPM for System Auditing
RPM can be used for system integrity checking:
# Verify all installed packages
rpm -Va
# Save verification results
rpm -Va > system-audit.txt
# Compare changes over time
diff previous-audit.txt system-audit.txt
Congratulations! You have successfully installed RPM Packages. Thanks for using this tutorial for installing RPM Packages on your CentOS system. For additional help or useful information, we recommend you check the official RPM website.