Managing Packages with apt
apt is the package manager for Debian-based Linux distributions including Ubuntu, Debian, and Linux Mint.
Update Package Lists
apt update
Downloads the latest package lists from repositories. Run this before installing anything.
Upgrade Installed Packages
apt upgrade -y # Upgrade packages, keep existing configs
apt full-upgrade -y # Also handles dependency changes (may remove packages)
Install a Package
apt install nginx -y
Remove a Package
apt remove nginx # Remove but keep config files
apt purge nginx # Remove including config files
Remove Unused Dependencies
apt autoremove -y
Search for a Package
apt search nginx
apt-cache search php | grep mysql
Show Package Information
apt show nginx
List Installed Packages
apt list --installed
dpkg -l | grep nginx
Clean the Package Cache
apt clean # Removes all cached package files
apt autoclean # Removes only outdated cached packages
Add a PPA (Personal Package Archive)
add-apt-repository ppa:ondrej/php -y
apt update
apt install php8.2 -y
Hold a Package (Prevent Upgrades)
apt-mark hold nginx
apt-mark unhold nginx