Operations 9 min read

Master Linux Package Management: yum, apt, dpkg, rpm, and Source Compilation

This guide walks through Linux package management fundamentals, covering yum on RPM‑based systems, apt/apt‑get on Debian‑based systems, low‑level dpkg and rpm commands, and step‑by‑step source compilation with practical examples, tips, and a concise comparison of convenience, customizability, and required privileges.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Package Management: yum, apt, dpkg, rpm, and Source Compilation

YUM (RPM‑based distributions)

sudo yum clean all && sudo yum makecache

– Refresh repository metadata. sudo yum install <package_name>[-<version>] – Install a package (optional version). sudo yum upgrade <package_name> – Upgrade a specific package. sudo yum update – Upgrade all installed packages. sudo yum remove <package_name> – Uninstall a package. sudo yum downgrade <package_name>-<version> – Downgrade to a specific version. yum search <keyword> – Search the repositories. yum list installed [<package_name>] – List installed packages (filter optional). yum list <package_name> --showduplicates – Show all available versions of a package.

sudo yum versionlock add <package_name>[-<version>]

– Lock a package to a specific version. sudo yum versionlock delete <package_name> – Remove a version lock. sudo yum versionlock clear – Remove all version locks. yum versionlock list – List currently locked packages.

Tip: Install the version‑lock plugin with sudo yum install yum-plugin-versionlock before using the version‑lock commands.

APT / APT‑GET (Debian‑based distributions)

sudo apt edit-sources [<source_file>]

– Edit the repository source list. sudo apt update or sudo apt‑get update – Refresh package indexes. sudo apt install <package_name>[=<version>] – Install a package (optional exact version). sudo apt upgrade <package_name> – Upgrade a specific package. sudo apt remove <package_name> – Uninstall a package. sudo apt purge <package_name> – Remove a package and its configuration files. apt list [<package_name>] -i – List installed packages (filter optional). apt‑cache search <keyword> --names-only – Search package names. apt‑cache show <package_name> – Display detailed package information. sudo apt‑get -f install – Fix broken dependencies. sudo apt‑get autoremove – Remove automatically installed packages that are no longer needed. apt‑cache policy <package_name> – Show the candidate version and all available versions. apt list <package_name> -a – List all available versions. apt‑cache madison <package_name> – Alternate view of all versions. sudo apt‑mark hold <package_name> – Prevent a package from being upgraded. sudo apt‑mark unhold <package_name> – Release a hold. apt‑mark showhold – Show all held packages.

Low‑level package tools (dpkg / rpm)

sudo dpkg -i <file.deb> [--force-depends]

– Install a .deb file (optional force). sudo dpkg -r <package_name> – Remove a package, leaving configuration files. sudo dpkg -P <package_name> – Purge a package (remove configuration files as well). dpkg -l <package_name> – List package status information. sudo dpkg‑query -W "<pattern>" – Query installed packages matching a pattern. dpkg -s <package_name> – Show detailed status of a package. dpkg -L <package_name> – List files installed by the package. dpkg -S <file_path> – Find which installed package owns a file. sudo rpm -ivh <file.rpm> – Install an RPM package. sudo rpm -Uvh <file.rpm> – Upgrade (or install) an RPM package. sudo rpm -e [--nodeps] <package_name> – Erase an RPM package, optionally ignoring dependencies. rpm -qa <package_name> – Query all installed RPM packages (filter optional). rpm -qi <package_name> – Show detailed information about an RPM package. rpm -ql <package_name> – List files belonging to an RPM package. rpm -qf <file_path> – Identify the RPM package that provides a given file.

Compiling and installing from source (nginx example)

Download the source archive and extract it:

wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzvf nginx-1.24.0.tar.gz
cd nginx-1.24.0

Install build dependencies (example for CentOS/RHEL): sudo yum install pcre-devel zlib-devel Configure, compile, and install:

./configure --prefix=/usr/local/nginx   # set installation prefix; add other flags as needed
make
sudo make install

Verify the installation and test start/stop:

/usr/local/nginx/sbin/nginx -v          # show version
sudo /usr/local/nginx/sbin/nginx -s stop  # stop a running instance

Optional: create a symbolic link so the binary is in the standard PATH:

sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
nginx -v

Uninstall manually if needed (most source packages do not provide an uninstall target):

sudo rm -f /usr/sbin/nginx
sudo rm -rf /usr/local/nginx
# If the Makefile defines an uninstall target, you can also run:
# sudo make uninstall

When installing from source you must manage dependencies yourself and clean up files manually.

Conclusion

Convenience: APT/apt‑get provides the most automated dependency handling, followed by YUM. Direct use of dpkg/rpm or source compilation requires manual dependency resolution.

Customizability: Building from source offers the highest degree of customization (configure flags, module selection). dpkg/rpm provide moderate flexibility, while APT/apt‑get installs pre‑built binaries with default options.

Required privileges: Source compilation can be performed with a regular user for the build step, but installation (e.g., make install) typically needs root. dpkg/rpm and APT/apt‑get require root for installation, removal, and upgrades.

Reference: https://www.cnblogs.com/librarookie/p/18617956
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

APTpackage managementRPMyumSource Compilationdpkg
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.