How to Install and Use RPM Packages Without Root Access: A Developer’s Guide


2 views

Many developers working in restricted environments face the challenge of installing RPM packages without root privileges. While RPM traditionally requires admin rights, several workarounds exist for non-root users who need to manage software packages.

The primary restriction comes from RPM's default behavior of installing to system directories like /usr/bin or /usr/lib, which require root access. However, we can redirect these installations to user-writable locations.

The simplest approach extracts RPM contents without installation:

rpm2cpio package.rpm | cpio -idmv

This extracts files to the current directory, preserving directory structure. You can then:

export PATH=$PATH:$(pwd)/usr/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/usr/lib

Some RPMs support relocation through the --prefix flag:

rpm -ivh --prefix=$HOME/rpminstall package.rpm

Then configure environment variables accordingly:

export PATH=$PATH:$HOME/rpminstall/bin
export MANPATH=$MANPATH:$HOME/rpminstall/share/man

For developers needing to rebuild packages with custom paths:

rpmbuild --rebuild --define "_topdir $HOME/rpmbuild" package.src.rpm

This creates RPMs specifically built for your user directory structure.

When dealing with dependencies, consider creating a local repository:

mkdir -p $HOME/rpm-repo
createrepo $HOME/rpm-repo

Then modify your ~/.rpmmacros:

%_topdir      %(echo $HOME)/rpmbuild
%_dbpath      %(echo $HOME)/rpmdb
%_install_langs en
%_excludedocs 1

Here's a complete workflow for installing Python:

# Extract to custom location
mkdir -p $HOME/python-install
rpm2cpio python3.rpm | (cd $HOME/python-install && cpio -idmv)

# Set environment
export PATH=$HOME/python-install/usr/bin:$PATH
export PYTHONHOME=$HOME/python-install/usr

Be aware that some packages might still fail due to:

  • Hardcoded paths in binaries
  • Requirement for system services
  • User namespace restrictions

Working in enterprise environments or shared hosting often means dealing with restricted root access. While RPM is traditionally a root-privileged package manager, developers frequently need to install or query packages without sudo permissions. Let's explore practical solutions.

Two primary approaches exist for RPM operations without root:

# Method 1: RPM with --prefix flag
rpm -ivh --prefix=$HOME/local package.rpm

# Method 2: Using rpm2cpio for extraction
rpm2cpio package.rpm | cpio -idmv

Create a personal RPM database and installation directory:

mkdir -p $HOME/rpm/{BUILD,RPMS,SOURCES,SPECS}
echo "%_topdir $HOME/rpm" > $HOME/.rpmmacros
rpmdb --initdb --dbpath $HOME/rpmdb

Here's how to install Python3 locally using extracted RPM:

wget http://example.com/python3.rpm
mkdir $HOME/python3
rpm2cpio python3.rpm | (cd $HOME/python3 && cpio -idmv)

# Set environment variables
export PATH=$HOME/python3/usr/bin:$PATH
export LD_LIBRARY_PATH=$HOME/python3/usr/lib64:$LD_LIBRARY_PATH

Even without root, you can inspect packages:

rpm --dbpath $HOME/rpmdb -qpi package.rpm
rpm --dbpath $HOME/rpmdb -qpl package.rpm

Missing dependencies often cause issues. Use this script to check requirements:

rpm -qpR package.rpm | while read dep; do
    if ! rpm --dbpath $HOME/rpmdb -q "$dep"; then
        echo "Missing dependency: $dep"
    fi
done

For developers needing to rebuild packages:

mkdir -p $HOME/mock
mock --rootdir=$HOME/mock --init
mock --rootdir=$HOME/mock --rebuild package.src.rpm

Local RPM databases have tradeoffs:

  • Slower query performance (no system-wide cache)
  • No automatic dependency resolution
  • Manual PATH and LD_LIBRARY_PATH management required