Terry : Package Managers

Linux Package Managers

Commands

Basic queries

Action

RPM

DEB

Ebuild

Pacman

List of all installed packages

rpm -qa

dpkg -l

equery list

pacman -Qi

List of installed packages matching substr

rpm -qa *substr*

dpkg -l *substr*

equery list substr

pacman -Q | grep substr

Basic information about an installed package

rpm -qi package

dpkg -p package

eix package

pacman -Qi package

List of files in a given package

rpm -ql package

repoquery -l package

repoquery --list package

dpkg -L package

apt-file list package

equery files package

pacman -Ql package

Advanced queries

Action

RPM

DEB

Ebuild

Pacman

Which package a file belongs to?

rpm -qf /path/to/file

yum provides | whatprovides file

dpkg -S file

apt-file search | find file

equery belongs file

pacman -Qo file

Check the hash sums of an installed package

rpm -V package

debsums -ca package

equery check package

 

Show pre/post install/uninstall scripts from a package

rpm -q --scripts package

less /var/lib/dpkg/info/package.{pre,post,config}*

cat `equery which package`

 

Show change log for a package

rpm -q --changelog package

zcat /usr/share/doc/package/changelog.Debian.gz

aptitude [-t release] changelog package

view /usr/portage/category/package/ChangeLog

pacman -Qc package

Local package installation/upgrade/removal

Action

RPM

DEB

Ebuild

Pacman

Install a package from local package_file

rpm -ihv package_file*.rpm OR URL

yum localinstall package_file*.rpm 

zypper in /path/to/package_file*.rpm OR URL

dpkg -i package_file*.deb

emerge --usepkg | -k package

emerge --usepkgonly | -K package

pacman -U package

Upgrade a package from local package_file

rpm -Uhv package_file*.rpm

dpkg -i package_file*.deb

emerge --update --usepkg | -k package

emerge --update --usepkgonly | -K package

pacman -U package

Remove an installed package

rpm -e package

yum remove | erase package

zypper rm -u package

dpkg -r package

dpkg -P package

apt-get remove --purge package

apt-get purge package

emerge --unmerge package

emerge --prune package

pacman -R package

pacman -Rs package

pacman -Rsc package

Package installation from repositories

Action

RPM

DEB

Ebuild

Pacman

Install a package

yum install package

rpm -i package

apt-get update && apt-get install package

aptitude update && aptitude install package

emerge -av package

pacman -S package

Install debug information files for a package

debuginfo-install package

apt-get build-dep linux
NOTE: for building the kernel 

FEATURES="splitdebug installsources" emerge -av package

 

Only download a package from repository, do not install

yum install yum-downloadonly

yum install | update package -y --downloadonly --downloaddir=/opt


apt-get install --download-only --reinstall package

apt-get download package (to pwd)

aptitude download package

emerge -avf package

pacman -Sw package

NOTE: in /var/cache/pacman/pkg/

Get information about package interdependencies

Action

RPM

DEB

Ebuild

Pacman

What a given package provides?

rpm -q --provides package

rpm -ql package

dpkg -s package

dpkg -L package

apt-cache show package

dpkg-query -W -f='${Provides}\n' package

equery files package

NOTE: package must be installed first.

pacman -Ql package

NOTE: package must be installed first.

What a given package requires?

rpm -q --requires package

rpm -qi package

dpkg -s package

apt-cache depends package

dpkg-query -W -f='${Depends}\n' package

equery depgraph --depth=1 package

pacman -Si package

 

Which installed package(s) provide a given dependency?

rpm -q --whatprovides dependency

dpkg -s package

apt-cache show package

dpkg-query -W -f='${Package}: ${Provides}\n' '*' | grep ': .*package'

equery belongs dependency

 

Which installed package(s) require a given dependency?

rpm -q --whatrequires dependency

dpkg -s package

apt-cache rdepends package

aptitude why package

 dpkg-query -W -f='${Package}: ${Depends}\n' '*' | grep ': .*package'

equery depends package

pacman -Qi package | grep Required

Show what prevents installation of a package

yum rpm tells with --verbose option -v

aptitude why-not package

emerge -pv package

 

Get package source files

yumdownloader --source package

apt-get source package

emerge -f package

abs repository/package

Working with package files

Action

RPM

DEB

Ebuild

Pacman

Unpack a package file to local directory

rpm2cpio file.rpm | cpio -id

rpm2cpio file.rpm | cpio -idmv

dpkg -x file.deb .

ar -x file.deb

N/A

tar -xzvf package (package.pkg.tar.gz)

tar -xJvf package (package.pkg.tar.xz)

Check package file integrity (checksums, signatures...)

rpm -K file.rpm

debsums package

emerge -f package

 

Show package metadatarpm -qip file.rpm

dpkg -I /path/to/file.deb

dpkg --info /path/to/archive.deb

  
Show package file list

rpm -qlvp /path/to/file.rpm

rpm -ql package (if installed)

dpkg -c file.deb

dpkg -L package (if installed)

 

tar -Jtvf package.pkg.tar.xz

pacman -Ql package (if installed)

Repository queries

Action

RPM

DEB

Ebuild

Pacman

Find a package in a repository which /path/to/file belongs to

yum provides | whatprovides /path/to/file

zypper wp /path/to/file

zypper se --provides --match-exact

zypper se --provides $(which command)

dlocate /path/to/file

dlocate $(which command)

OPTIONAL:
apt-file update
apt-file search /some/file

N/A

pacman -Qo /path/to/file

pacman -Qo $(which command)

Find a package based on some string or part of the describing string

yum search *substr*

zypper se *substr*

apt-cache search *substr*

eix -S substr

pacman -Ss substr

Shows the full description of package

yum info package

zypper info package

apt-cache show package

eix package

pacman -Si package

Orphaned packages

Cleaning up orphaned packages

Arch Linux

Arch Linux
pacman -Qqdt | xargs pacman -Rsc --noconfirm

NOTE: May need to run this a couple of times until pacman -Qqdt produces no output.

Ubuntu / Debian

Ubuntu / Debian
# remove packages that were automatically installed to satisfy dependencies
# for other packages and are now no longer needed
apt-get autoremove

# purge orphaned packages
deborphan | xargs apt-get purge -y

# purge configuration files
aptitude purge '~c'

NOTE: Run deborphan until it produces no output.

RHEL / CentOS / Oracle Linux / Fedora

RHEL / CentOS / Oracle Linux / Fedora
package-cleanup --leaves | xargs yum -y erase

NOTE: Run package-cleanup --leaves until no output is produced.

openSUSE

openSUSE
# Remove orphaned packages
rpmorphan | xargs zypper rm -u -n

# Double check
zypper pa --orpahend | awk '{ print $5 }' | xargs zypper rm -u -n

# NOT recommended
zypper pa --unneeded | awk '{ print $5 }' | xargs zypper rm -u -n

NOTE: Run rpmorphan until it produces no output.

IMPORTANT: Be careful with zypper pa --unneeded option.

Relevant directories and files

Red Hat, Fedora, Oracle Linux, CentOS

yum config: /etc/yum.conf

yum repos: /etc/yum.repos.d

rpm configs and macros: /etc/rpm, /usr/lib/rpm

rpm database: /var/lib/rpm/

YUM cache: /var/cache/yum

Debian/Ubuntu

List of repositories and mirror sites: /etc/apt/sources.list and /etc/apt/sources.list.d/

apt database: /var/lib/apt/lists

apt local cache: /var/cache/apt

Gentoo

emerge configs: /etc/make.conf, /etc/portage/

Portage tree: /usr/portage

Binary packages (FEATURES="buildpkg" enabled in make.conf): /usr/portage/packages

Default directory to download sources to: /usr/portage/distfiles

Default Portage working directory: /var/lib/portage/

Arch Linux

pacman config: /etc/pacman.conf, /etc/pacman.d/ 

mirror list: /etc/pacman.d/mirrorlist

local database: /var/lib/pacman/local/

pacman cache: /var/cache/pacman/

pacman log: /var/log/pacman.log

openSUSE

zypper config: /etc/zypp/zypp.conf, /etc/zypp/zypper.conf

zypper repos: /etc/zypp/repos.d/

rpm configs and macros: /etc/rpm/, /usr/lib/rpm/

RPM database: /var/lib/rpm/

zypper local cache: /var/cache/zypper/

Reference

Package managers