Quick take: Use sudo apt update to refresh the package lists, sudo apt upgrade to update installed software, sudo apt install name to add a package, and sudo apt remove name to uninstall it.
Introduction
The apt command is the package manager for Debian and Ubuntu, handling installation, updates, and removal of software from the distribution's repositories. It resolves dependencies automatically, so a single apt install pulls in everything a package needs.
This guide covers the everyday package operations — updating, upgrading, installing, removing, and searching — plus the cleanup commands that keep a system tidy.
Syntax
The basic syntax of the apt command is:
apt [OPTIONS] COMMAND [PACKAGE...]Common Options and Parameters
The most useful options and parameters for the apt command:
| Option | Description |
|---|---|
| update | Refresh the list of available packages and versions. |
| upgrade | Install the newest versions of installed packages. |
| full-upgrade | Upgrade, removing packages if needed to resolve dependencies. |
| install PKG | Install a package and its dependencies. |
| remove PKG | Uninstall a package (keep its config files). |
| purge PKG | Uninstall a package and remove its config files. |
| autoremove | Remove dependencies that are no longer needed. |
| search TERM | Search for packages by name or description. |
| show PKG | Show details about a package. |
Practical Examples
Real apt commands you can run today:
# Refresh package lists
sudo apt update
# Upgrade all installed packages
sudo apt upgrade
# Update and upgrade in one line
sudo apt update && sudo apt upgrade -y
# Install a package
sudo apt install nginx
# Remove a package and its config
sudo apt purge nginx
# Search for a package
apt search 'image editor'
# Clean up unused dependencies
sudo apt autoremoveTips and Best Practices
- Always run
apt updatebeforeapt installorupgradeso you get current package versions. - Use
apt purgerather thanremovewhen you want a package's configuration files gone as well. aptis the modern, friendlier front end; the olderapt-getandapt-cachestill work and are preferred in scripts for stable output.
Final Thoughts
apt is the command that installs, updates, and removes software on Ubuntu and Debian, handling dependencies so you do not have to. Memorise the core verbs — update, upgrade, install, remove/purge, and autoremove — and you can manage a system's software confidently. For lower-level work with individual .deb files, reach for dpkg.
FAQ: apt Command in Linux
What is the difference between apt update and apt upgrade?+
apt update refreshes the local list of available packages and their versions but installs nothing. apt upgrade then installs the newer versions. You normally run update first, then upgrade.
How do I install a package with apt?+
Use sudo apt install packagename. apt downloads the package and any dependencies and installs them. Run sudo apt update first to ensure current versions.
What is the difference between apt remove and apt purge?+
remove uninstalls the package but keeps its system-wide configuration files. purge removes the package and its configuration files, giving a cleaner removal.
How do I search for a package?+
Use apt search term to find packages by name or description, then apt show packagename to see details before installing.
What does apt autoremove do?+
It removes packages that were installed automatically as dependencies but are no longer required by anything, freeing disk space and keeping the system clean.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support