$linuxjunkies
>

apt-get(8)

apt-get is the command-line tool for managing packages in Debian-based Linux distributions.

UbuntuDebianFedoraArch

Synopsis

apt-get [OPTION]... COMMAND [PACKAGE]...

Description

apt-get is the primary package management tool for Debian, Ubuntu, and other apt-based systems. It handles downloading, installing, upgrading, and removing software packages from configured repositories.

Common commands include: update (refresh package lists), install (download and install packages), upgrade (install newer versions), remove (uninstall packages), and clean (free up disk space by removing cached packages).

Most operations require superuser privileges (use sudo). Package names are case-sensitive and typically lowercase.

Common options

FlagWhat it does
updaterefresh the list of available packages from repositories
upgradeinstall newer versions of packages already on the system
installdownload and install specified packages
removeuninstall packages but keep configuration files
purgeuninstall packages and delete all configuration files
autoremoveremove unused packages that are no longer needed as dependencies
cleanremove cached package files to free disk space
-y, --assume-yesassume 'yes' to all prompts; useful for scripting
-s, --simulateshow what would be done without actually making changes
--no-upgradedo not upgrade packages marked for upgrade

Examples

refresh package lists from all configured repositories; run before install or upgrade operations

sudo apt-get update

download and install the nginx web server and its dependencies

sudo apt-get install nginx

upgrade all packages to their newest available versions without removing packages

sudo apt-get upgrade

install the build-essential package automatically confirming the prompt

sudo apt-get install -y build-essential

uninstall the apache2 package while preserving its configuration files

sudo apt-get remove apache2

remove automatically installed dependency packages no longer needed by any installed package

sudo apt-get autoremove

simulate installing python3-pip to see what would happen without making actual changes

sudo apt-get install -s python3-pip

remove all cached packages and only keep cache for currently installed packages to free disk space

sudo apt-get clean && sudo apt-get autoclean

Related commands