Use apt Command In Linux (Examples)

apt command in Linux is basically a command line tool that allows users to install, update, remove and manage various deb packages on Linux platforms. While using this command, it’s mostly combined with other tools as well like apt-get or apt-cache with various default values of some options.

Since the apt command offers a high-level Command Line Interface (CLI) for managing system and packages, it is better suited for interactive usage by default in compare to other specialised APT utilities as aforementioned.

Syntax to use apt command in Linux

apt [...COMMANDS] [...PACKAGES]

Note: It’s suggested to run most of the apt command with user account having sudo privileges.

Various apt commands that are mostly used in Linux (Examples)

sudo apt update

The APT package index is actually a database which holds records of all available packages from the repositories enabled on system. So, in order to update them, users can run the above command, and it will the latest changes from enabled APT repositories.

sudo apt upgrade

The second mostly used command to update Linux system frequently, that is also considered as the most important factor to assure overall system’s security. Running the above command will upgrade all installed packages to latest versions. However, the command will not upgrade those packages which require removal of installed packages. In order to do so, users can run “sudo apt upgrade package_name”.

sudo apt full-upgrade

Using the above command, it will remove installed packages if it requires to upgrade the whole system. It’s noteworthy to be cautious while using this command.

sudo apt install package_name package_name2

This command is basically used to install package/packages by running a single command. Users can install multiple packages at once with a single command, all they need to specify the packages separated with a space as mentioned in the command above. To install a single, just need to specify a single package_name.

sudo apt install /path/to/file.deb

The above mentioned command is better to install a local deb files. Just suppose you have downloaded a deb file and want to install it on local computer, just run the command and mention the complete path to downloaded file.

sudo apt remove package_name package_name2

In order to remove an installed packages, the command can be useful. Alike apt install command to install packages, users can also specify multiple packages as well to remove them with a single command.

Once the command is executed, it will deinstall the specified packages from the system, however its configuration files will remain on the system. In order to remove all those configuration files as well, users should execute “sudo apt purge package_name” in the command line.

sudo apt autoremove

The above command is basically used to remove such packages which are installed as dependencies on system. So, when all such packages are required to be removed as well, it’s suggested to run the above command.

sudo apt list

As mentioned above, the list command used with apt allows users to list all available, installed and upgradeable packages. The users can also use grep command along with the above command to filter the output shown by apt list command. (Exapmle: sudo apt list | grep package_name)

sudo apt list –installed

Above command can be used to list only those packages which are installed on system.

sudo apt list –upgradeable

Using this command, the users can check for those packages on the system which can be upgradeable.

sudo apt search package_name

Users can choose this command in order to search for a given package in the list of installed or available packages on system. In case if it finds such packages, will display it on screen.

sudo apt show package_name

With the above command, users an look for information about given package using show command with apt. this can be helpful for those who are looking for information about package dependencies, its size, and more other details before removing it.