- Unix Commands Reference
- Unix Commands - Home
apt Command in Linux
Advanced Package Tool, also called apt is a command-line utility that allows you to manage deb packages on your Linux systems, including Ubuntu, Debian, and related Linux distributions. With the apt command, you can install, update, and remove software packages on your system.
Table of Contents
Syntax for apt Command in Linux
By default, the apt command line tool is installed on all Debian-based Linux distributions like Ubuntu, Debian, Kali Linux, Ubuntu Mint, and other such distributions. You can confirm the apt installation on your Linux system by using the following command −
apt --version
The apt command has different uses on Linux systems and has different syntaxes in terms of use. However, it should be noted that if you are a regular user, you must use the apt command with sudo privileges to operate. The root users can use the apt command without sudo privileges. The general syntax to use the apt command in your Linux system is provided below −
sudo apt [options]
Where options are different parameters, you can use the apt command and add additional as well based on your usage. We will discuss these options in the next section of apt command usage on Linux systems.
How to use apt Command in Linux?
As previously mentioned, the apt command can be used in different ways according to the user's needs. Some of the most widely used apt commands in Linux systems is to −
- Check Packages Updates
- Upgrade Packages
- Install Applications
- Reinstall Applications
- Remove Applications
- List Installed Packages
- Find Packages Information
- Search for Packages
- Shows Package Dependencies
- List Available Versions
- Cleanup Cache
- Fix Broken Dependencies
- Install Deb Files
Check Packages Updates
With the apt command, you can check for the package updates installed in your apt repository. It will be helpful to keep your system up to date. To update your packages' repository list on the Linux system, you can run the below-given apt command −
sudo apt update
The above command will check for all package updates available in your system repository. If you want to check the package update of a specified package, you can do this by using the below-given command −
sudo apt list --upgradable
Upgrade Packages
Another common use of apt command on Linux is to upgrade the packages that are installed on your system. You can do the packages’ upgradation on Linux by using the following command −
sudo apt upgrade
You can also perform a full system upgrade by replacing update with the full-upgrade command, as given below −
sudo apt full-upgrade
The full-upgrade command is similar to upgrade, however, it handles package removals and dependency changes and is useful for more significant updates.
Alternatively, you can also use the dist-upgrade command to upgrade your package on a Linux system −
sudo apt dist-upgrade
The dist-upgrade command handles complex package upgrades, including changing dependencies, and is more aggressive than the full-upgrade command.
Install Applications
You can also use the apt command on Linux to install applications or packages on the system. You can do this by adding the install option with the apt command, followed by the application name you want to install on your system.
sudo apt install [application_name]
For example, if you want to install an application called VLC media player on your Linux system, you can do so from the below-given command −
sudo apt install vlc
Reinstall Applications
If you are experiencing an issue running an application on your system, you can reinstall it with the apt command. The syntax to reinstall an application with the apt command on Linux is given below −
sudo apt install --reinstall [application_name]
As an example, we are reinstalling vlc again on Linux using the following command −
sudo apt install --reinstall vlc
Remove Applications
With the apt command, you can also remove applications from your system. You can do this by adding the remove option after the apt command and then the application name you want to remove from the system. The syntax to remove an application from the Linux system with the apt command is provided below −
sudo apt remove [application_name]
For example, to remove an application called VLC media player from Linux system, you can use the following command −
sudo apt remove vlc
Alternatively, you can also use the purge option instead of remove to delete the application from your system −
sudo apt purge [application_name]
If you want to remove an application with all its dependencies from the system, then use the autoremove option with the apt command, as provided below −
sudo apt autoremove [application_name]
List Installed Packages
Besides updating, upgrading, installing, and removing packages, you can also use the apt command to list the installed packages on your system. The command to list all installed packages on the Linux system is provided below −
sudo apt list --installed
To search for a specific package on Linux, you can use the below-given apt command −
sudo apt list --installed | grep [package_name]
If you want to view the list of installed packages one page at a time, then use the following command −
sudo apt list --installed | less
Find Packages Information
If you want to find detailed information about a package in the Linux repository, then use the apt show command with the application or package name you want to search. The syntax to find package information from the Linux repository is provided below −
apt show <package_name>
Search for Packages
If packages are installed on your Linux system, and you want to search for information about these packages, then use the apt search command with the package or application name −
apt search <package_name>
Shows Package Dependencies
If you want to display the dependencies associated with a package, you can use the apt depends command with the package or application name. The syntax for such a process is provided below −
apt depends [package_name]
If you want to find out which packages depend on other packages, use the apt rdepends command instead of depends, as shown below −
apt rdepends [package_name]
List Available Versions
If you want to display the list of all available versions on your Linux system, you can use the apt list command with the --all-versions −
sudo apt list --all-versions
Cleanup Cache
Over time, your Linux system accumulates the downloaded package files in the cache, however, you can clean it with the apt clean command provided below −
sudo apt clean
This command will delete all the downloaded deb files from the package cache, without affecting your pre installed packages on the system.
Fix Broken Dependencies
You can also use the apt command on Linux to fix the broken packages that may hinder your installation process. To fix the broken packages, use the apt install command followed by the -f option −
sudo apt install -f
This command will attempt to resolve dependency issues by installing packages missing from the system or removing conflicting ones.
Install Deb Files
Deb files are the packages that allow you to install an application on your Debian-based systems. You download the deb file of an application and then install it either from the GUI, dpkg command, or using the apt command. The apt command is recommended because it resolves the dependencies automatically.
To install the deb file on your Linux system, use the below-given apt install command −
sudo apt install ./package_name.deb
The ./ before the filename in the above command ensures that apt will look for the Deb file in the current directory of your Linux system.
There are some more additional options you can add with the apt command which are provided in the table given below −
Option | Descriptions | Example |
---|---|---|
dselect-upgrade | Upgrade packages using the dselect package selection GUI. | sudo apt install deselect-upgrade |
check | Used to verify the integrity of the package files. | sudo apt check |
download | Used to download package files without actually installing them. | sudo apt download [package_name] |
source | Used to download the source code for a package. | sudo apt source [package_name] |
--no-install-recommends | Prevents the installation of recommended packages. | sudo apt --no-install-recommends install [package_name] |
-d or –download-only | Downloads package files without installing them. | sudo apt-d [package_name] |
-q or –quiet | Suppresses most output messages will package installation and upgradation. | sudo apt -q install [package_name] |
--show-progress | Shows the progress bar in percentage during package downloads. | sudo apt --show-progress update |
--no-upgrade | Prevents the installation of new packages instead upgrades only existing packages. | sudo apt-get install [package_name] –no-upgrade |
Conclusion
The apt command is a powerful utility for managing, installing, updating and removing packages on Linux systems. You can use the apt command to check for package updates, upgrade the packages, install, reinstall and remove the application from your system. Apart from that, you can also list installed packages, find package information, show packages dependencies and list available options.
Not only that, you can also clean up cache, fix broken dependencies and install deb files on your system from the apt command. A few more additional options can also be used to get your desired output from the apt command. Don’t forget to use sudo in case you are login as a regular user because some of the apt commands will not work without sudo privileges.