Yum install vs localinstall: Key Differences When Installing Local RPM Packages on CentOS/RHEL 7


2 views

When working with local RPM packages on CentOS/RHEL 7 systems, both yum install and yum localinstall can be used, but they behave differently in dependency resolution:

# Basic syntax for both commands
sudo yum install /path/to/package.rpm
sudo yum localinstall /path/to/package.rpm

The primary distinction lies in how each command handles dependencies:

# Example scenario with a package requiring dependencies
# Using yum install:
# Will attempt to find dependencies in enabled repositories first
sudo yum install /tmp/mypackage-1.0-1.el7.x86_64.rpm

# Using yum localinstall:
# Will treat the local RPM as part of the repository and may find additional local deps
sudo yum localinstall /tmp/mypackage-1.0-1.el7.x86_64.rpm

In real-world usage, these differences manifest in several ways:

  • yum install is more strict about repository sources
  • yum localinstall can sometimes resolve dependencies from other local RPMs
  • Both commands will install the specified package if no dependencies exist

When dealing with complex local package installations:

# First attempt with standard install
sudo yum install /tmp/package.rpm

# If dependency issues occur, try localinstall
sudo yum localinstall /tmp/package.rpm

# For maximum control, specify all dependent packages
sudo yum localinstall /tmp/package.rpm /tmp/dep1.rpm /tmp/dep2.rpm

The technical implementation differs in these aspects:

  • Repository priority handling
  • Dependency resolution algorithms
  • Transaction set creation

When working with CentOS/RHEL systems, you'll often need to install RPM packages from local storage. The yum package manager provides two similar but distinct approaches:

sudo yum install /path/to/package.rpm
sudo yum localinstall /path/to/package.rpm

The primary distinction lies in dependency resolution:

  • yum install: Treats the local RPM as if it were coming from a repository, resolving dependencies from configured repos
  • yum localinstall: First installs the specified local RPM, then attempts to resolve dependencies from repositories

Scenario 1: Installing with dependencies already in repos

# Both commands behave similarly when dependencies are available
sudo yum install /tmp/nginx-1.20.1-1.el7.x86_64.rpm
sudo yum localinstall /tmp/nginx-1.20.1-1.el7.x86_64.rpm

Scenario 2: Installing when dependencies are missing

# yum install may fail immediately if dependencies aren't found
sudo yum install /tmp/custom-app-2.3.4.rpm

# yum localinstall will install the package first, then look for dependencies
sudo yum localinstall /tmp/custom-app-2.3.4.rpm

The internal processing differs significantly:

  1. yum install:
    • Adds the local RPM to the transaction as if from a repo
    • Resolves all dependencies before any installation occurs
  2. yum localinstall:
    • Immediately installs the specified RPM
    • Then processes the RPM's dependencies in a separate step

For system stability, consider these approaches:

# 1. Always verify the package first
rpm -qpi /tmp/package.rpm

# 2. Check dependencies before installation
rpm -qpR /tmp/package.rpm

# 3. For complex installations, create a local repository
sudo yum-config-manager --add-repo=file:///path/to/local_repo

Note that in newer versions (RHEL 8+/CentOS 8+), dnf has replaced yum as the default package manager. The behavior remains similar, but with improved dependency resolution:

# Modern equivalent in RHEL 8+
sudo dnf install ./package.rpm

For legacy systems still running yum, understanding these differences remains crucial for package management.