2.8 KiB
📦 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.
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.
apt upgrade
🔍 2. Searching and Viewing Packages
apt show <package>
Displays detailed information about a specific package, including version, dependencies, description, and more.
apt show <package>
apt list
Lists packages based on various filters (e.g., installed, upgradable, available). Running it without arguments shows all packages.
apt list
apt-cache search <pkg name>
Searches the package cache for packages matching the given name or description. Useful for discovering packages related to a topic or function.
apt-cache search <pkg name>
📥 3. Installing and Reinstalling Packages
apt install <pkg name>
Installs a package and its dependencies from the repositories.
apt install <pkg name>
apt reinstall <package>
Reinstalls the specified package. This is useful if files from a package are accidentally deleted or corrupted.
apt reinstall <package>
❌ 4. Removing Packages
apt remove <package>
Removes the specified package but retains configuration files. Useful when planning to reinstall later without losing settings.
apt remove <package>
apt purge <package>
Completely removes the package along with its configuration files. Use when you want a clean uninstallation.
apt purge <package>
apt autoremove
Automatically removes packages that were installed as dependencies but are no longer needed.
apt autoremove
🛠️ 5. Advanced Package Handling
apt install -f
Attempts to fix broken dependencies by installing missing packages. Often used after a failed install.
apt install -f
apt install --download-only <package>
Downloads a package without installing it. The downloaded .deb files are saved in:
/var/cache/apt/archives/
Example:
apt install --download-only <package>
✅ Final Notes
- Always start with
sudo apt updatebefore any install or upgrade. - Use
apt-cache searchwhen unsure of a package’s exact name. - Be cautious with
purgeas it deletes config files too.