乐闻世界logo
搜索文章和话题

What are the usage methods and common operations of Linux package management tools (APT, YUM, PACMAN)?

2月17日 23:37

Linux package management is a core skill for system maintenance and software installation, with different distributions using different package management tools.

Debian/Ubuntu package management (APT):

  • apt update: update package list
  • apt upgrade: upgrade installed packages
  • apt full-upgrade: upgrade packages (may remove dependency packages)
  • apt install package: install package
  • apt remove package: remove package (keep configuration files)
  • apt purge package: remove package and its configuration files
  • apt autoremove: remove no longer needed dependency packages
  • apt search keyword: search for packages
  • apt show package: display detailed package information
  • apt list --installed: list installed packages
  • apt-cache depends package: view package dependencies
  • apt-cache rdepends package: view other packages that depend on this package
  • dpkg -l: list installed packages
  • dpkg -i package.deb: install .deb file
  • dpkg -r package: remove package
  • dpkg -P package: remove package and its configuration files

CentOS/RHEL package management (YUM/DNF):

  • yum update: update package list and installed packages
  • yum install package: install package
  • yum remove package: remove package
  • yum search keyword: search for packages
  • yum info package: display detailed package information
  • yum list installed: list installed packages
  • yum provides command: find package that provides a specific command
  • yum check-update: check for updatable packages
  • yum clean all: clean cache
  • yum deplist package: view package dependencies
  • rpm -qa: list all installed packages
  • rpm -ivh package.rpm: install .rpm file
  • rpm -e package: remove package
  • rpm -q package: query if package is installed
  • rpm -ql package: list files installed by package
  • rpm -qf file: find which package a file belongs to

Arch Linux package management (PACMAN):

  • pacman -Syu: sync package database and upgrade system
  • pacman -S package: install package
  • pacman -R package: remove package
  • pacman -Rs package: remove package and its dependencies
  • pacman -Rns package: remove package, dependencies, and configuration files
  • pacman -Ss keyword: search for packages
  • pacman -Si package: display detailed package information
  • pacman -Qe: list explicitly installed packages
  • pacman -Qm: list packages installed from AUR
  • pacman -Fy: sync file database
  • pacman -Fo command: find package that provides a specific command

Software repository configuration:

  • Debian/Ubuntu: /etc/apt/sources.list and /etc/apt/sources.list.d/
  • CentOS/RHEL: /etc/yum.repos.d/
  • Arch Linux: /etc/pacman.conf

Third-party software repositories:

  • EPEL (Extra Packages for Enterprise Linux): provides additional packages for RHEL/CentOS
  • PPA (Personal Package Archive): Ubuntu user personal software repository
  • AUR (Arch User Repository): Arch Linux user software repository

Package management best practices:

  • Regularly update system: apt update && apt upgrade or yum update
  • Use version locking: apt-mark hold package or yum versionlock package
  • Clean cache: apt autoremove && apt clean or yum clean all
  • Backup important configurations: backup /etc directory before upgrading
  • Test environment verification: verify in test environment before updating production
  • Use automation tools: Ansible, Chef, Puppet for batch management

Common problem solving:

  • Dependency conflicts: use apt -f install or yum --skip-broken
  • Corrupted packages: use dpkg --configure -a or yum reinstall package
  • Lock issues: delete /var/lib/dpkg/lock or /var/run/yum.pid
  • Package not found: check repository configuration, run apt update or yum makecache
标签:Linux