Common Commands:
The apt tool provides several commands for package management:
update
: Update the package list from repositories
upgrade
: Upgrade installed packages to newer versions
full-upgrade
: Upgrade packages, even if it requires removing other packages (similar to dist-upgrade
in apt-get)
install
: Install new packages
remove
: Remove packages while keeping configuration files
purge
: Remove packages along with their configuration files
autoremove
: Remove automatically installed packages that are no longer needed
search
: Search for packages by name or description
show
: Display detailed information about packages
list
: List packages based on criteria (installed, upgradable, etc.)
edit-sources
: Edit sources.list using the default editor
clean
: Remove downloaded package files from the local cache
autoclean
: Remove obsolete downloaded package files
Apt vs Apt-get:
The apt
command was designed as a more user-friendly alternative to apt-get
and apt-cache
:
- More intuitive command structure and simplified options
- Progress bar display for better usability
- Color output for better readability
- Combines commonly used features from apt-get, apt-cache, and apt-config
- Designed for interactive use, while apt-get is better for scripting
Package Management Tips:
- Always run
sudo apt update
before installing or upgrading packages to ensure you have the latest package information
- Use
apt list --installed
to see all installed packages
- Use
apt show package-name
to view detailed information about a package before installing it
- Add
-y
flag to automatically answer yes to prompts in scripts (e.g., sudo apt install -y package-name
)
- Use
apt search
with grep for more specific searches: apt search text-editor | grep gtk
- The
apt full-upgrade
command is similar to apt-get dist-upgrade
and should be used with caution
Configuration:
APT uses several configuration files:
/etc/apt/sources.list
: Main file listing package repositories
/etc/apt/sources.list.d/
: Directory containing additional repository configuration files
/etc/apt/apt.conf
and /etc/apt/apt.conf.d/
: Configuration files for APT behavior
/etc/apt/preferences
and /etc/apt/preferences.d/
: Package pinning configuration
Package States:
Understanding package states can help manage your system:
- Installed: Package is installed on the system
- Upgradable: A newer version is available in the repositories
- Held: Package is marked to not be upgraded automatically
- Removable: Package installed but not required by other packages
- Auto-removable: Package installed automatically but no longer required
Managing Package Versions:
To install a specific version of a package:
sudo apt install package-name=version
To prevent a package from being upgraded:
sudo apt-mark hold package-name
To allow a held package to be upgraded again:
sudo apt-mark unhold package-name
Important Notes:
- Always use
sudo
when making changes to the system through apt
- Be careful when using
--allow-downgrades
as it can potentially break dependencies
- Use
apt --simulate install package-name
to see what would happen without making changes
- For scripting and automated tasks, apt-get is still recommended over apt
- The apt cache is stored in
/var/cache/apt/archives/
- Always check the suggested/recommended packages to avoid installing unnecessary software
- When in doubt, use
apt show
to get details about a package before installation