The apt (Advanced Package Tool) command is a powerful package management tool used in Debian-based Linux distributions like Ubuntu. It simplifies the process of installing, updating, upgrading, and managing software packages.
# Update package lists
apt update
# Upgrade all installed packages
apt upgrade -y
# Upgrade with dependency resolution (may remove packages)
apt dist-upgrade -y
# Upgrade to a new release (if available)
apt full-upgrade -y# Install a single package
apt install <package_name>
# Install multiple packages at once
apt install <package1> <package2> <package3>
# Install a specific version
apt install <package_name>=<version>
# Install from a local .deb file
apt install ./package_name.deb
# Reinstall a package
apt reinstall <package_name># Remove a package (keeps config files)
apt remove <package_name>
# Remove a package and its config files
apt purge <package_name>
# Remove unnecessary dependencies
apt autoremove -y# Search for a package
apt search <keyword>
# Show package details
apt show <package_name>
# List installed packages
apt list --installed
# List packages with updates available
apt list --upgradable# Clean package cache (removes all cached .deb files)
apt clean
# Clean old package cache (only outdated .deb files)
apt autoclean
# Remove unused dependencies
apt autoremove# Fix broken dependencies
apt --fix-broken install
# Reconfigure a broken package
dpkg-reconfigure <package_name>
# Check package status
dpkg -l | grep <package_name>
# Force remove a problematic package
dpkg --remove --force-remove-reinstreq <package_name># Download a package without installing
apt download <package_name>
# Mark a package to prevent updates
apt-mark hold <package_name>
# Unhold a package
apt-mark unhold <package_name>
# Check package priority
apt-cache policy <package_name># Update, upgrade, and remove unnecessary packages in one go
apt update && apt upgrade -y && apt autoremove -y && apt clean
# Find and install multiple related packages
apt search <keyword> | grep <specific_term> | awk '{print $1}' | xargs apt install -y
# List the top 10 largest installed packages
dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr | head -n 10