Linux apt command

apt is a command-line program for installing, updating, removing, and managing deb packages on Ubuntu, Debian

3 min read
By myfreax
Linux apt command
Linux apt command

apt is a command-line program for installing, updating, removing, and managing deb packages on Ubuntu, Debian, and Debian Linux built distributions.

This tutorial serves as a quick reference document for the apt command.

It combines the most commonly used commands from the apt-get and apt-cache tools with options and defaults. The apt command must be run as a user with sudo authority.

apt is designed to be used interactively with users. But it's best to use apt-get and apt-cache in your Shell scripts because they are backward compatible between versions and have more options and features.

The APT package index is a database that contains records of packages available in enabled repositories on the system. To update the package index.

The sudo apt update command retrieves the latest index data from the APT repository.

It is always recommended that you run the update package index once before upgrading or installing a new package.

Apt upgrade

Updating your Linux system regularly is one of the most important aspects of overall system security.

The sudo apt upgrade command upgrades installed packages to the latest version. This command does not upgrade the dependencies of those packages that have been removed.

If you want to upgrade a single package, pass the package name, such as the command sudo apt upgrade package_name.

Configuring automatic installation of security updates is a good practice.

The difference between upgrade and full-upgrade is that full-upgrade upgrades the entire system. Use caution when running the sudo apt full-upgrade command.

Apt  install

Installing the apt package is as simple as running the sudo apt install package_name command.

If you are installing multiple packages, specify them as a space-separated list, sudo apt install package1 package2.

To install a local deb file, provide the full path to the file. Otherwise, the apt command will attempt to retrieve and install the package from the APT repository.

The sudo apt install /full/path/file.deb command will install the deb file /full/path/file.deb.

Apt remove

To delete installed packages, you can use the apt subcommands remove and purge.

The remove subcommand will uninstall the specified software package, but may leave some configuration files behind.

To delete software including its configuration files, use purge instead of remove, which will delete the software configuration files along with it.

sudo apt remove package_name will remove a single package. You can also specify multiple packages, separated by Spaces.

For example, run the sudo apt remove package1 package2 command.

The sudo apt purge package_name command will purge the software's configuration files along with it.

Apt autoremove

Dependent packages are also installed whenever a software package is installed on the system.

After a software package is deleted, the dependencies remain on the system. These packages are no longer used by other programs and can be deleted.

sudo apt autoremove will remove unwanted dependencies.

Apt list

The apt list command allows you to list installed and upgradeable packages. To list all available software packages,

The sudo apt list command prints a list of all packages, including information about their versions and structures.

To determine if the specified package is installed, use the grep command to filter the output. sudo apt list | grep package_name.

The sudo apt list --installed command lists only installed packages.

Before upgrading a software package, use sudo apt list --upgradeable to get a list of upgradeable software packages, which is useful when deciding whether to upgrade or not.

The sudo apt search package_name command lets you search for a specific package in a list of available software sources.

If the package is found, the package whose name matches the search term is returned.

If your search results include a number of packages, you may need to show more packages to determine whether to install them.

The sudo apt show package_name command determines the package dependency, installation size, and package source.

Knowing how to manage packages is an important part of Linux system administration. To learn more about the apt command, open the terminal and type man apt.

Please feel free to comment if you have any questions.