apt command in linux with examples
Last Updated :
23 Sep, 2024
apt provides a high-level Command Line Interface (CLI) for the APT package management system, offering a user-friendly interface intended for interactive use. It simplifies common tasks like installation, upgrades, and removal, with better defaults than more specialized tools like apt-get and apt-cache.
Syntax
apt [...COMMANDS] [...PACKAGES]
Where,
- COMMANDS represent the actions you wish to perform, such as install, update, or remove
- PACKAGES refer to the specific software you want to manage by name
Most Commonly Used ‘apt’ Commands
1. Update:
The apt update command is used to refresh the package database, ensuring you have the latest information from all configured repositories before installing or upgrading any packages. It does not install or upgrade any packages but prepares your system to do so.
Syntax:
apt update
2. Upgrade:
This command is used when we want to install available upgrades of all packages currently installed on the system from the sources configured via sources.list.
If new packages are required to satisfy dependencies, they will be installed, but already existing packages will never be removed. If for a package to be upgraded, the removal of an installed package is required, the upgrade will not be performed.
Syntax:
apt upgrade
3. Full-upgrade:
This command has a functionality similar to upgrade but if to upgrade the system as a whole, if the removal of already installed packages is required, then it will remove them.
Syntax:
apt full-upgrade
4. Install:
This command performs the action of installation on one or more packages specified via regex, glob or exact match. The user can select a specific version of the package to be installed by following the package name with ‘equals’ sign and specifying the version number.
Also, the user can specify the version from a specific release by following the package name with a forward slash (/) and the codename (stretch, buster, sid, etc.) or the suite name (stable, testing, unstable).
Syntax:
apt install [...PACKAGES]
5. Remove:
This command is similar to install command, the only difference being that the remove command removes the packages instead of installing them.
Syntax:
apt remove [...PACKAGES]
6. Purge:
This command is similar to remove command, the only difference being that the purge command also removes any configuration files related to the removed packages.
Syntax:
apt purge [...PACKAGES]
7. Autoremove:
This command is used when the user wants to remove the packages that were installed as dependencies to previously installed packages, and are no longer required by the system, as the packages which required them as dependencies were removed, or the dependencies were changed.
The packages which the user explicitly installs via apt install are never proposed for automatic removal.
Syntax:
apt autoremove
8. Search:
This command is used when the user wants to search for the given regex term(s) in the list of available packages and display matches. For example, this command can be useful when you want to search for packages having a specific feature. Syntax:
apt search [...REGEX]
9. Show:
This command is used when the user wants to display information regarding packages like it’s dependencies, download and installation size, the sources from which the package is available, the package’s content’s description and more.
It can be helpful to display the information before the user removes the package, or while searching for a package to install.
Syntax:
apt show [...PACKAGES]
Output:

10. List:
This command is used to display a list of packages that satisfy a certain criteria. It is similar to dpkg-query –list in that manner. It has a support for glob patterns for matching the package names and options to list the installed (–installed), upgradeable (–upgradeable) or all-available versions (–all-versions).
Syntax:
apt list [--installed/--upgradeable/--all-versions]
11. Edit-sources:
This command lets you edit your sources.list files in your preferred text editor and also provides basic sanity checks. Syntax:
apt edit-sources
Commonly Used apt Options
1. –help:
Displays a detailed overview of the available commands and options for the apt utility.
apt --help
2. –version:
This option shows the current version of the apt utility installed on your system.
apt --version


Conclusion
The ‘apt’ command is a vital tool for managing software packages in Linux systems. From installing and upgrading software to removing unneeded dependencies, it streamlines package management for both novice and advanced users. Mastering the ‘apt’ command can significantly improve your efficiency in handling software on Linux.
apt command in linux – FAQs
How is apt different from apt-get and apt-cache?
apt is designed as a simpler and more user-friendly front-end for package management compared to apt-get and apt-cache. It combines the functionalities of both, making common tasks like installation and upgrades easier for interactive use.
Is there any difference between apt upgrade and apt full-upgrade?
Yes, while both commands upgrade installed packages, apt full-upgrade allows for the removal of existing packages if required for the upgrade, whereas apt upgrade does not.
Can I specify a package version during installation?
Yes, with the apt install command, you can specify a particular version of a package by appending = and the version number to the package name.
What does apt autoremove do?
The apt autoremove command removes packages that were installed as dependencies for other packages but are no longer needed.
Master DevOps and also get 90% Course fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.
The most sought-after Three 90 challenge has started and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!
Similar Reads
access command in linux with examples
The 'access' command in Linux is a system call used to determine whether the calling process has access to a specified file or directory. This function is useful for checking file permissions, including whether a file exists, and if it can be read, written, or executed by the process. The check is p
5 min read
accton command in Linux with Examples
'accton' is one of important Linux/Unix command which is used by the administrator to monitor user activities. It is used to turn on or turn off the process for accounting or change the info process accounting file. When the command is run in the terminal without any argument, it stops the process a
2 min read
aclocal command in Linux with Examples
aclocal command in Linux is used to automatically generate 'aclocal.m4' files from configure.in file. automake in Linux contain a lot of autoconf macros that can be used in the different packages. These macros must be defined in the aclocal.m4. If not, then it can’t be accessed by the autoconf. The
3 min read
ACPI command in Linux with examples
ACPI is the command in Linux that helps the users in managing power settings. It also helps in monitoring the hardware status efficiently. It facilitates with providing essential information such as battery health, CPU temperatures, and fan speeds, providing support in system maintenance and perform
4 min read
acpi_available command in Linux with examples
acpi_available is a command in Linux that tests whether the ACPI (Advanced Configuration and Power Interface) subsystem is available or not. Syntax$ acpi_availableReturn Statuses of acpi_availableThe command returns one of three possible statuses: Status 0: Indicates that the ACPI subsystem is avail
2 min read
acpid command in Linux with Examples
The acpid daemon provides intelligent power management on a system and allows to query battery and configuration status by supporting the Advanced Configuration and Power Interface (ACPI). The ACPI events are notified to the user-space programs by acpid. The ACPI (Advanced Configuration and Power In
3 min read
addr2line command in Linux with Examples
'addr2line' command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the 'objdump' command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with th
4 min read
agetty command in Linux with Examples
agetty is a Linux version of getty. getty short for "get tty" is a Unix program running on a host computer that manages physical or virtual terminals to allow multi-user access. Linux provides a virtual terminal(tty) which is similar to the regular Linux terminal. agetty command opens a virtual term
4 min read
How to Create and Use Alias Command in Linux
Imagine you're lost in a maze of complicated Linux commands. You stumble upon a secret doorway marked "Alias," and inside you find shortcuts to all your favorite commands! That's what creating aliases is like. You get to make your own mini-commands for the long ones you use all the time, making thin
6 min read
amixer command in Linux with Examples
amixer is a command-line mixer for ALSA(Advanced Linux Sound Architecture) sound-card driver . amixer can support multiple soundcards. amixer with no arguments will display the current mixer settings for the default soundcard as well as the device. This is a good way to see a list of the simple mixe
2 min read
aplay command in Linux with examples
aplay is a command-line audio player for ALSA(Advanced Linux Sound Architecture) sound card drivers. It supports several file formats and multiple soundcards with multiple devices. It is basically used to play audio on command-line interface. aplay is much the same as arecord only it plays instead o
2 min read
aplaymidi Command in Linux with Examples
aplaymidi command in Linux is used to play standard MIDI(Musical Instrument Digital Interface) files, by sending the content of a MIDI file to an ALSA(Advanced Linux Sound Architecture) MIDI port, sound renderer like timidity or a hardware MIDI device is required to play MIDI files. Syntaxaplaymidi
3 min read
apropos command in Linux with Examples
Linux/Unix comes with a huge number of commands and thus it become quite difficult sometimes to remember each and every command. apropos command becomes useful in such cases. apropos command helps the user when they don't remember the exact command but knows a few keywords related to the command tha
3 min read
apt command in linux with examples
apt provides a high-level Command Line Interface (CLI) for the APT package management system, offering a user-friendly interface intended for interactive use. It simplifies common tasks like installation, upgrades, and removal, with better defaults than more specialized tools like apt-get and apt-ca
5 min read
apt-get command in Linux with Examples
The command-line tool `apt-get` is the most popular package management tool used in our Debian-based Linux operating system. This article provides an overview of `apt-get` and its basic syntax. It will include the most commonly used commands, their syntax, description, and examples. It also gives an
15+ min read
aptitude command in Linux with examples
The aptitude command in Linux provides a user-friendly interface to interact with the machine's package manager. It functions similarly to a control panel, like in Windows, allowing you to install, upgrade, and remove packages. The command can be used in either a visual interface or directly via the
5 min read
ar command in Linux with examples
The 'ar' command in Linux is a versatile tool used for creating, modifying, and extracting files from archives. An archive is essentially a collection of files bundled together in a specific structure, making it easy to manage multiple files as a single entity. Each file within the archive is referr
5 min read
arch command in Linux with examples
The arch command is a simple yet powerful utility in Linux used to display the architecture of the system's hardware. By running this command, users can quickly determine the type of processor their system is running on, such as i386, x86_64, or arm. Knowing the architecture is crucial for installin
2 min read
arp command in Linux with examples
arp command manipulates the System's ARP cache. It also allows a complete dump of the ARP cache. ARP stands for Address Resolution Protocol. The primary function of this protocol is to resolve the IP address of a system to its mac address, and hence it works between level 2(Data link layer) and leve
2 min read
aspell command in Linux with examples
aspell command is used as a spell checker in Linux. Generally, it will scan the given files or anything from standard input then it check for misspellings. Finally, it allows the user to correct the words interactively. Spell checking is crucial when working with large documents, coding, or writing
3 min read
atd command in Linux with examples
atd is a job scheduler daemon that runs jobs scheduled for later execution. These jobs are one-time task(not recurring) at a specific time scheduled using 'at' or 'batch' utility. Syntax: atd [-l load_avg] [-b batch_interval] [-d] [-f] [-s] Options: -l : Specifies a limiting load factor, over which
2 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version
1 min read
atq command in linux with examples
atq displays the list of pending jobs which are scheduled by the user. If the user is the superuser then the pending jobs of all the users will be displayed. The output lines display Job number, date, hour, queue, and username for each job. Syntax: atq [-V] [-q queue] Options: -V: It will display th
2 min read
autoconf command in Linux with examples
autoconf command is used in Linux to generate configuration scripts. Generate a configuration script from a TEMPLATE-FILE if given, or from ‘configure.ac’ if present, or 'configure.in'. The output is sent to the standard output if TEMPLATE-FILE is given, otherwise, it is sent into ‘configure’. To us
1 min read
autoheader command in Linux with Examples
autoheader command in Linux is used to create a template file of C “#define” or any other template header for configure to use. If the user will give autoheader an argument, it reads the standard input instead of reading configure.ac and also writes the header file to the standard output. This comma
3 min read