Problem Statement
Explain advanced package management including repository configuration, package dependencies, and resolving package conflicts.
Explanation
Repository configuration for Debian/Ubuntu in /etc/apt/sources.list and /etc/apt/sources.list.d/*.list. Format: deb http://repo.url/ubuntu focal main restricted adds repository for Ubuntu 20.04 (focal). Components: main (officially supported), restricted (proprietary drivers), universe (community maintained), multiverse (restricted by copyright). Add PPA (Personal Package Archive): add-apt-repository ppa:user/repo adds third-party repository.
RHEL/CentOS repository configuration in /etc/yum.repos.d/*.repo. Format: [repo-id] name=Repository Name, baseurl=http://repo.url, enabled=1, gpgcheck=1, gpgkey=http://repo.url/RPM-GPG-KEY. Add EPEL (Extra Packages for Enterprise Linux): yum install epel-release adds additional packages not in official repos. Import GPG keys: rpm --import keyfile verifies package authenticity.
Dependency management: apt/yum automatically resolve dependencies installing required packages. Check dependencies: apt-cache depends package or yum deplist package. Reverse dependencies: apt-cache rdepends package shows packages depending on this one. Broken dependencies: apt --fix-broken install or yum check resolves issues. Hold packages from upgrade: apt-mark hold package or yum versionlock add package.
Package conflicts occur when packages provide same files or have incompatible dependencies. Resolve by: identifying conflicting packages (dpkg -S filename shows which package owns file), removing one conflicting package, using alternatives system (update-alternatives --config program selects default), or building from source if packaged versions conflict. Force installation with dpkg --force-overwrite or rpm --force (use cautiously - can break system).
Best practices: keep systems updated (security patches), enable automatic security updates, test updates on non-production first, use stable repositories for production (avoid testing/unstable), document custom repositories and packages, backup before major upgrades, monitor package changelogs for breaking changes, and clean package cache periodically (apt clean, yum clean all). Understanding package management prevents dependency hell and maintains stable systems.