| by Arround The Web | No comments

How to Use apt Linux Command – Examples

apt (Advanced Package tool) is a straightforward way of managing packages on the system. It is a command-line utility for installing, updating, upgrading, and removing packages from Linux-based systems. The apt command must be run with sudo privileges for performing a specific task.

In this guide, we will discuss the apt Linux command with different examples on the Linux system.

apt Linux Commands with Examples

The basic syntax of the apt command is as follows:

sudo apt <command>

apt command allows you to run the command with different arguments:

Options Description
-d Only download a specific package
-y Answer yes to prompts
-f Fix broken dependencies
-h Help guide
–assume-no Answer no to all prompts
-s Displays output only without altering the system

Example 1: Install a Package Using apt Command

To install a package from Linux repository, you must follow the below-given apt syntax by replacing the package name according to your choice.

sudo apt install <package-name>

Here I am using the apt install command for installing the PlayOnLinux on Linux:

sudo apt install playonlinux

Example 2: Update System Using apt Command

The apt update command updates all the packages present in the repository. Always execute this command before installing a new package on your system to get the latest version of it:

sudo apt update

Example 3: Upgrade Packages Using apt Command

When you run the upgrade command without specifying the package name it will upgrade all the packages of the system.

sudo apt upgrade

If you specify the name of the package with the upgrade command it will upgrade only that package. The following command will upgrade the installed package of Bluetooth:

sudo apt --only-upgrade install bluetooth

Example 4: Search Package Using the apt Command


The following command will display the name and descriptions of the available packages for a specified search term. The basic syntax of the search option with the apt is:

apt search <package-name>

Search the Bluetooth in the list of all available packages and display matches via the following command:

apt search bluetooth

Example 5: Clean System Using apt Command

Whenever we run the apt command, the cache is stored in the specific folder of your system. It takes up space in your system. The cleaning using the apt command will free up the disk and remove packages from the folder|:

sudo apt clean

Example 6: Get the List of the Packages via apt Command

To get the list of all the upgradeable packages of your system, execute the following command:

sudo apt list –-upgradable

To get the list of all the packages in the repository, use the following command:

sudo apt list | more

Example 7: Remove a Package Using apt Command

The apt with the remove command will remove the binaries of packages. The following remove command of apt will remove the package with all its dependencies from your Linux system:

apt remove --autoremove playonlinux

The removing packages will remove the data from the system but leave the user configuration files behind. Use purge to get rid of all the leftover files from your system:

sudo apt purge <packagename>

The following purge command will remove everything related to PlayOnLinux package including the configuration files:

sudo apt purge playonlinux

Bottom Line

Knowing how to manage packages is an important part of the Linux system. In Linux, we use the apt package manager for installing, removing, and updating the packages from the Linux repository. The apt command can be used in different ways and the above guide will show you some examples of using the apt command in Linux for performing a specific task on the system.

Share Button

Source: linuxhint.com

Leave a Reply