CentOSLinuxTutorials

How To Install RPM Packages on CentOS

Install RPM Packages on CentOS

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.

Table of Contents

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:

  1. Always verify the source website’s authenticity
  2. Use HTTPS connections when available
  3. Compare checksums or GPG signatures before installation
  4. 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

  1. Download the RPM package to your system:
    wget https://example.com/path/to/package.rpm
  2. Check for dependencies before installation:
    rpm -qpR package.rpm
  3. Install the package:
    sudo rpm -ivh package.rpm
  4. 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:

  1. Analyzes the package’s dependencies
  2. Checks installed packages to see what’s missing
  3. Searches configured repositories for the needed dependencies
  4. Creates a transaction set including all required packages
  5. Prompts for confirmation before proceeding
  6. 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

  1. Check if the package is listed as installed:
    rpm -q package-name
  2. Verify the package version:
    rpm -q package-name --qf "%{VERSION}\n"
  3. Check the full package information:
    rpm -qi package-name
  4. List files installed by the package:
    rpm -ql package-name
  5. Verify package file integrity:
    rpm -V package-name

Understanding Verification Output

When using rpm -V, output indicates changes since installation:

  • . (dot): Test passed
  • S: File size differs
  • M: Mode differs (includes permissions and file type)
  • 5: MD5 sum differs
  • D: Device major/minor number mismatch
  • L: Symbolic link path mismatch
  • U: User ownership differs
  • G: Group ownership differs
  • T: 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:

  1. Identify conflicting packages:
    sudo yum check
  2. Consider using --allowerasing with dnf to resolve conflicts automatically:
    sudo dnf install package-name --allowerasing
  3. 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:

  1. Identify the missing dependencies:
    rpm -qpR package.rpm
  2. Install them manually or use yum/dnf:
    sudo yum install dependency1 dependency2
  3. Then retry the original installation:
    sudo yum localinstall package.rpm

Package Conflicts and Resolution Strategies

For package conflicts:

  1. Use more powerful dependency resolution:
    sudo dnf install package-name --best --allowerasing
  2. Consider using a different package version:
    sudo dnf install package-name-1.2.3
  3. In extreme cases, exclude conflicting packages:
    sudo dnf install package-name --exclude=conflicting-package

Handling Version Compatibility Issues

When dealing with version incompatibilities:

  1. Check available versions:
    yum --showduplicates list package-name
  2. Specify the desired version:
    sudo yum install package-name-1.2.3
  3. Consider adding version-specific repositories

Dealing with Corrupted Packages

For corrupted packages:

  1. Clear the yum/dnf cache:
    sudo yum clean all
    # or
    sudo dnf clean all
  2. Re-download the package:
    yumdownloader package-name
  3. Verify the package integrity:
    rpm --checksig package.rpm

Permission Problems

Common permission issues include:

  1. Not using sudo/root privileges (solution: prefix commands with sudo)
  2. SELinux blocking installations (check with ausearch -m avc)
  3. 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

  1. Navigate to the downloaded RPM file in the file manager
  2. Right-click on the file
  3. Select “Open with Software Install”
  4. Follow the prompts to complete the installation

The Software Center Application

  1. Launch Software Center from the Applications menu
  2. Use the search function to find desired software
  3. Click “Install” next to the package name
  4. 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:

  1. Regular system updates (weekly or monthly)
  2. Testing updates in non-production environments first
  3. Maintaining consistent package versions across similar systems
  4. Documenting custom package installations and configurations

Security Considerations

Enhance security by:

  1. Only installing packages from trusted sources
  2. Verifying package signatures before installation
  3. Keeping packages updated to patch security vulnerabilities
  4. 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:

  1. Install and test in development environments
  2. Use snapshot functionality if available (like in virtual environments)
  3. Create a test plan covering critical functionality
  4. 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.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button