# 📦 Managing Packages with `apt` on Debian/Ubuntu The `apt` (Advanced Package Tool) command-line utility allows you to manage software on Debian-based Linux systems. Below are essential `apt` commands grouped by purpose, with clear explanations for each. --- ## 🔄 1. Updating and Upgrading the System ### `sudo apt update` Fetches the latest package lists from repositories. This ensures your system is aware of the newest available versions of packages. ```bash sudo apt update ``` --- ### `apt upgrade` Installs the newest versions of all installed packages based on the updated package lists. It does **not** remove or install any other packages. ```bash apt upgrade ``` --- ## 🔍 2. Searching and Viewing Packages ### `apt show ` Displays detailed information about a specific package, including version, dependencies, description, and more. ```bash apt show ``` --- ### `apt list` Lists packages based on various filters (e.g., installed, upgradable, available). Running it without arguments shows all packages. ```bash apt list ``` --- ### `apt-cache search ` Searches the package cache for packages matching the given name or description. Useful for discovering packages related to a topic or function. ```bash apt-cache search ``` --- ## 📥 3. Installing and Reinstalling Packages ### `apt install ` Installs a package and its dependencies from the repositories. ```bash apt install ``` --- ### `apt reinstall ` Reinstalls the specified package. This is useful if files from a package are accidentally deleted or corrupted. ```bash apt reinstall ``` --- ## ❌ 4. Removing Packages ### `apt remove ` Removes the specified package but **retains configuration files**. Useful when planning to reinstall later without losing settings. ```bash apt remove ``` --- ### `apt purge ` Completely removes the package **along with its configuration files**. Use when you want a clean uninstallation. ```bash apt purge ``` --- ### `apt autoremove` Automatically removes packages that were installed as dependencies but are no longer needed. ```bash apt autoremove ``` --- ## 🛠️ 5. Advanced Package Handling ### `apt install -f` Attempts to **fix broken dependencies** by installing missing packages. Often used after a failed install. ```bash apt install -f ``` --- ### `apt install --download-only ` Downloads a package without installing it. The downloaded `.deb` files are saved in: ```bash /var/cache/apt/archives/ ``` Example: ```bash apt install --download-only ``` --- ## ✅ Final Notes * Always start with `sudo apt update` before any install or upgrade. * Use `apt-cache search` when unsure of a package’s exact name. * Be cautious with `purge` as it deletes config files too.