Linux apt Command
apt (Advanced Packaging Tool) is a shell-frontend package manager in Debian and Ubuntu.
The apt command provides commands to find, install, upgrade, and remove individual, multiple, or all packages, with concise and memorable commands.
The apt command requires superuser (root) privileges to execute.
apt Syntax
apt [options] [command] [package ...]
options: Optional, include -h (help), -y (assume yes to all prompts), -q (quiet mode), etc.
command: The operation to perform.
package: The package name to install.
Common apt Commands
List all available updates:
sudo apt update
Upgrade packages:
sudo apt upgrade
List updatable packages and version information:
apt list --upgradeable
Upgrade packages, removing old packages before updating:
sudo apt full-upgrade
Install a specific package:
sudo apt install <package_name>
Install multiple packages:
sudo apt install <package_1> <package_2> <package_3>
Update a specific package:
sudo apt update <package_name>
Show detailed information about a package, such as version, installation size, dependencies, etc.:
sudo apt show <package_name>
Remove a package:
sudo apt remove <package_name>
Clean up unused dependencies and library files:
sudo apt autoremove
Remove a package and its configuration files:
sudo apt purge <package_name>
Search for a package:
sudo apt search <keyword>
List all installed packages:
apt list --installed
List all installed packages with version information:
apt list --all-versions
Examples
Check for available updates:
sudo apt update
Upgrade packages:
sudo apt upgrade
Enter Y to start the upgrade during the interactive prompt.
Combine the following two commands for a one-click upgrade:
sudo apt update && sudo apt upgrade -y
Install the mplayer package:
sudo apt install mplayer
If you don't remember the full package name, you can enter the first part and press Tab
to list related packages.
In the example above, entering reds and pressing Tab
lists four related packages.
To install a package without upgrading it if it already exists, use the --no-upgrade
option:
sudo apt install <package_name> --no-upgrade
Install mplayer without upgrading if it exists:
sudo apt install mplayer --no-upgrade
To upgrade without installing, use the --only-upgrade
option:
sudo apt install <package_name> --only-upgrade
Upgrade mplayer only, without installing if it doesn't exist:
sudo apt install mplayer --only-upgrade
To specify a version, use the following syntax:
sudo apt install <package_name>=<version_number>
packagename is the package name, and versionnumber is the version number.
Remove a package using the remove command:
sudo apt remove mplayer
Search for packages related to libimobile:
apt search libimobile
Show information about the pinta package:
apt show pinta
List updatable packages:
apt list --upgradeable
Clean up unused dependencies and library files:
sudo apt autoremove
Enter Y to start the cleanup during the interactive prompt.