apt-get
apt-get
The apt-get
command is a powerful package management tool used in Debian-based Linux distributions, such as Debian, Ubuntu, and their derivatives. It allows users to install, update, upgrade, and remove software packages from the system's repositories.
Basic Commands
Update Package List
Before installing or upgrading packages, you should update the package list to ensure you have the latest information about available packages:
sudo apt-get update
Upgrade Packages
To upgrade all installed packages to their latest versions, use:
sudo apt-get upgrade
To perform a more comprehensive upgrade that may install or remove packages to satisfy dependencies, use:
sudo apt-get dist-upgrade
Install a Package
To install a specific package, use:
sudo apt-get install package_name
For example, to install the curl
package:
sudo apt-get install curl
Remove a Package
To remove a specific package, use:
sudo apt-get remove package_name
To remove a package along with its configuration files, use:
sudo apt-get purge package_name
Clean Up
To remove packages that were automatically installed to satisfy dependencies for other packages and are no longer needed:
sudo apt-get autoremove
To clean the local repository of retrieved package files:
sudo apt-get clean
To remove all packages that have been downloaded but are no longer installed:
sudo apt-get autoclean
Advanced Commands
Search for Packages
To search for a package by name or description:
apt-cache search keyword
Show Package Information
To display detailed information about a package:
apt-cache show package_name
Check for Broken Dependencies
To check for broken dependencies and attempt to fix them:
sudo apt-get check
Download a Package Without Installing
To download a package without installing it:
sudo apt-get download package_name
Upgrade the Distribution
To perform a distribution upgrade, which includes upgrading to a new release of the operating system:
sudo apt-get dist-upgrade
Example Usage
Update and Upgrade
To update the package list and upgrade all installed packages:
sudo apt-get update
sudo apt-get upgrade
Install Multiple Packages
To install multiple packages at once, list them separated by spaces:
sudo apt-get install package1 package2 package3
Remove Multiple Packages
To remove multiple packages at once:
sudo apt-get remove package1 package2 package3
Common Options
-y
: Assume "yes" to all prompts and run non-interactively.-f
: Attempt to correct a system with broken dependencies.--purge
: Remove configuration files when removing packages.-d
: Download only; do not install or unpack archives.--no-install-recommends
: Do not consider recommended packages as a dependency for installing.
For example, to install a package without recommended packages:
sudo apt-get install --no-install-recommends package_name
Conclusion
The apt-get
command is a versatile and essential tool for managing software packages on Debian-based systems. By understanding its basic and advanced commands, you can effectively install, update, upgrade, and remove packages, ensuring your system stays up-to-date and free of unnecessary software.
help
Usage: apt-get [options] command
apt-get [options] install|remove pkg1 [pkg2 ...]
apt-get [options] source pkg1 [pkg2 ...]
apt-get is a command line interface for retrieval of packages
and information about them from authenticated sources and
for installation, upgrade and removal of packages together
with their dependencies.
Most used commands:
update - Retrieve new lists of packages
upgrade - Perform an upgrade
install - Install new packages (pkg is libc6 not libc6.deb)
reinstall - Reinstall packages (pkg is libc6 not libc6.deb)
remove - Remove packages
purge - Remove packages and config files
autoremove - Remove automatically all unused packages
dist-upgrade - Distribution upgrade, see apt-get(8)
dselect-upgrade - Follow dselect selections
build-dep - Configure build-dependencies for source packages
satisfy - Satisfy dependency strings
clean - Erase downloaded archive files
autoclean - Erase old downloaded archive files
check - Verify that there are no broken dependencies
source - Download source archives
download - Download the binary package into the current directory
changelog - Download and display the changelog for the given package
Last updated