Linux apt Command
apt (Advanced Packaging Tool) is a shell front-end package manager in Debian and Ubuntu.
The apt command provides commands to find, install, upgrade, and remove one, a group, or even all software packages, and the commands are concise and easy to remember.
Running apt commands requires superuser (root) privileges.
apt Syntax
apt [options] [command] [package ...]
- **options:** Optional; options include -h (help), -y (answer "yes" to all prompts during installation), -q (do not show the installation process), and so on.
- **command:** The operation to perform.
- package: The name of the package to install.
Common apt Commands
-
Command to list all upgradable software:sudo apt update
-
Upgrade packages:sudo apt upgrade
List upgradable packages and version information:apt list --upgradable
Upgrade packages, removing packages that need updating before upgrading:sudo apt full-upgrade
-
Command to install a specified piece of software:sudo apt install
Install multiple packages:sudo apt install
-
Command to update a specified piece of software:sudo apt update
-
Show detailed package information, such as version number, install size, dependencies, and so on:sudo apt show
-
Command to remove a package:sudo apt remove
-
Clean up dependencies and library files that are no longer used: sudo apt autoremove
-
Remove a package and its configuration files: sudo apt purge
-
Command to search for a package: sudo apt search
-
List all installed packages:apt list --installed
-
List version information of all installed packages:apt list --all-versions
Example
View some upgradable packages:
sudo apt update

Upgrade installed packages:
sudo apt upgrade

In the interactive prompt above, enter the letter Y to start the upgrade.
You can 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 quite remember the full package name, you can enter just the first part and press the Tab key; related package names will be listed:

In the example above, we entered reds, then pressed the Tab key, and four related packages were output.
If we want to install a package but not upgrade it if it already exists, we can use the --no-upgrade option:
sudo apt install --no-upgrade
Install mplayer, but do not upgrade it if it already exists:
sudo apt install mplayer --no-upgrade

If you only want to upgrade and not install, use the --only-upgrade option:
sudo apt install --only-upgrade
Only upgrade mplayer; if it does not exist, do not install it:
sudo apt install mplayer --only-upgrade

If you need to set a specific version, the syntax is as follows:
sudo apt install =
package_name is the package name,version_number is the version number.
To remove a package, you can use the remove command:
sudo apt remove mplayer

Find packages related to the name libimobile:
apt search libimobile

View information about the pinta package:
apt show pinta

List upgradable packages:
apt list --upgradeable

Clean up dependencies and library files that are no longer used:
sudo apt autoremove

In the interactive prompt above, enter the letter Y to start the cleanup.