Linux
Package Management
Installing and managing packages in Linux
Package Management
Package managers handle software installation, updates, and removal on Linux systems.
Debian/Ubuntu (APT)
Basic Commands
# Update package lists
sudo apt update
# Upgrade installed packages
sudo apt upgrade # upgrades to latest version
sudo apt full-upgrade # upgrades including removing packages
# Install a package
sudo apt install packagename
# Install multiple packages
sudo apt install package1 package2 package3
# Remove a package
sudo apt remove packagename
# Remove package and configuration
sudo apt purge packagename
# Remove unused dependencies
sudo apt autoremove
# Search for packages
apt search keyword
apt-cache search package
# Show package information
apt show packagename
apt-cache policy packagenameAdvanced Usage
# Hold a package from updates
sudo apt-mark hold packagename
# Unhold a package
sudo apt-mark unhold packagename
# Check package version
apt-cache policy packagename
# List installed packages
apt list --installed
# Fix broken dependencies
sudo apt --fix-broken installRed Hat/CentOS (YUM/DNF)
Basic Commands
# Update packages
sudo yum update # or dnf update
# Install a package
sudo yum install packagename
# Remove a package
sudo yum remove packagename
# Search for packages
sudo yum search keyword
# Show package information
sudo yum info packagename
# List installed packages
sudo yum list installedDNF (Newer alternative to YUM)
# Similar commands to yum
sudo dnf install packagename
sudo dnf update
sudo dnf remove packagenameAlpine Linux (APK)
# Update and install
apk update
apk add packagename
# Remove
apk del packagename
# Search
apk search keywordCommon Package Management Tasks
Installing from Source
# Download source
wget https://example.com/package.tar.gz
# Extract
tar -xzf package.tar.gz
cd package
# Compile and install
./configure
make
sudo make installManaging Services
# Start service
sudo systemctl start servicename
# Stop service
sudo systemctl stop servicename
# Enable on boot
sudo systemctl enable servicename
# Check status
sudo systemctl status servicename
# Restart service
sudo systemctl restart servicenameBest Practices
- Always run
apt updatebefore installing packages - Keep system updated regularly
- Remove unnecessary packages to reduce attack surface
- Use package managers instead of manual compilation when possible
- Pin critical package versions in production
- Automate updates with tools like unattended-upgrades
- Monitor package vulnerabilities
- Use proper package repositories
- Document custom package installations