
APT (Advanced Package Tool) is a powerful command-line package management system used in Debian, Ubuntu, and other Debian-based Linux distributions. This article covers the most common and useful apt commands that system administrators and Linux users should know.
Basic APT Commands
Updating Package Lists
sudo apt update
This command updates the package lists from repositories, ensuring you have information about the latest available packages.
Upgrading Installed Packages
sudo apt upgrade
Upgrades all installed packages to their latest versions.
To upgrade and install new dependencies or remove packages if required:
sudo apt full-upgrade
(Formerly known as apt-get dist-upgrade
)
Installing Packages
sudo apt install package_name
Installs a specific package and its dependencies.
Multiple packages can be installed simultaneously:
sudo apt install package1 package2 package3
Removing Packages
sudo apt remove package_name
Removes a package but keeps configuration files.
To completely remove a package including configuration files:
sudo apt purge package_name
Removing Unused Dependencies
sudo apt autoremove
Removes packages that were automatically installed to satisfy dependencies but are no longer needed.
Package Information Commands
Searching for Packages
apt search search_term
Searches for packages matching the given term in names and descriptions.
For more specific name-only searches:
apt search --names-only search_term
Viewing Package Details
apt show package_name
Displays detailed information about a specific package.
Listing Packages
apt list --installed
Lists all installed packages.
apt list --upgradable
Lists all installed packages that can be upgraded.
apt list --all-versions package_name
Shows all available versions of a specific package.
Advanced APT Commands
Working with Package Files
sudo apt download package_name
Downloads a package file without installing it.
sudo apt install ./path/to/package.deb
Installs a local .deb package file.
Cleaning APT Cache
sudo apt clean
Removes all cached packages from /var/cache/apt/archives/
.
sudo apt autoclean
Removes only outdated cached packages.
Fixing Broken Packages
sudo apt --fix-broken install
Attempts to fix broken dependencies.
Editing Sources
sudo apt edit-sources
Opens the sources.list file in the default editor.
APT Configuration and Information
Checking Dependency Information
apt depends package_name
Shows a list of dependencies for a package.
apt rdepends package_name
Shows packages that depend on the specified package.
Version Policy
apt policy package_name
Displays the installation candidate for a package and its priority.
Checking Package Contents
apt-file list package_name
Lists all files contained in a package (requires apt-file package).
Simulation Mode
sudo apt --simulate install package_name
Simulates the installation process without making any changes.
Less Common But Useful Commands
Holding Package Versions
sudo apt-mark hold package_name
Prevents a package from being automatically upgraded.
sudo apt-mark unhold package_name
Allows a held package to be upgraded again.
Viewing Changes
apt changelog package_name
Views the changelog for a specific package.
APT vs APT-GET
While apt-get
has been the traditional command, apt
was introduced as a more user-friendly interface, combining the most commonly used features of apt-get
, apt-cache
, and apt-config
.
Common apt-get
equivalents:
apt-get update
→apt update
apt-get upgrade
→apt upgrade
apt-get install
→apt install
apt-get remove
→apt remove
apt-cache search
→apt search
apt-cache show
→apt show
Conclusion
The apt
command is an essential tool for managing packages on Debian-based Linux distributions. Mastering these commands will help you efficiently manage software installation, updates, and removals on your Linux system. While this article covers most common use cases, you can always access the complete documentation by typing man apt
in your terminal.