How To Use APT Command in Linux

How to use the apt command in Linux to find and install new packages, update packages, delete packages and other actions.

What is APT?

Debian makes use of the distribution system dpkg, which is a packaging system through which programs and applications are provided for the installation of certain applications.

APT (Advanced Package Tool) is a command line tool that interacts with the packaging system and we currently have dpkg commands for its administration.

In this tutorial, we will use Ubuntu 16.04.

Update Packages Database

APT works with a database of available packages. If the database is not updated, the system will not know if there are new packages available, that is why we must run the repository update on any Linux system before performing a new installation.

Updating the package database requires superuser privileges, so it will be necessary to use sudo.
We will execute the following:

sudo apt update

At the time of execution, we can see several packages available on multiple servers.

Update Installed Packages

Once the package database has been updated, the next step will be to update the installed packages.

The most convenient way is to update all the packages that have available updates.

For this we will execute the following:

sudo apt upgrade

If we want to perform a complete update we can execute the following command:

sudo apt full-upgrade

The full update method works the same as the update, except that if the system update requires the removal of a package already installed on the system, it will do so, whereas the normal update command will not execute it.

Remember that apt update only updates the database of packages. If we want to perform a full system update we can execute the following line:
sudo apt update && sudo apt upgrade -y

How To Install New Packages with APT

The apt command offers us a simple way to install new packages in the system, for this we will execute the following syntax:

sudo apt install <package_name>

Simply enter the name of the desired package to start its installation:

sudo apt install mplayer

Install Multiple Packages with APT

In the case of being necessary to install different packages in the system, apt offers us the possibility of installing them in a single line and not one by one.

For this we will use the following syntax:

sudo apt install <package1> <package2> <package3>

Install Packages Without Update

This step applies when we want to install a package, but we do not want its update because it is already installed.

In this case, we will execute the following syntax:

sudo apt install <package-name> --no-upgrade

Update Packages Without Install Them

This option applies when we want to update a package but we do not want to install it in Linux, for this , we execute the following:

sudo apt install <package_name> --only-upgrade

Remove Packages using APT

Another of the frequent tasks we perform in Linux environments is to remove packages and applications that we no longer use as such.

For this apt offers us the safe uninstallation by executing the following syntax:

sudo apt remove <package_name>

Another way to uninstall packages in Linux is using the purge parameter, which we will use in the following way:

sudo apt purge <package_name>

Search For Linux Packages

On many occasions we may want to install a specific package for Linux but we do not have clear what is the specific name of this.

The apt command allows us to obtain a list of available packages with a specific term, for this we will use the following syntax:

apt search <end>

View Package Contents using APT

This option is practical when we want to obtain information about the package such as its dependencies, the size of installation and download, the different sources from which the package is available, the description of the contents of the package among other things.

For this we execute the following syntax:

apt show <package_name>

Get a List Of Updatable & Installed Packages

The apt command includes a new option called list which allows us to see all the packages that have a newer version ready to be updated, their syntax is.

apt list –upgradeable

We will be able to see all the packages installed in the system executing:

apt list –installed

Clean the System with APT

This command removes libraries and packages that were installed automatically to complete the dependencies of an installed package. If the package is deleted, these installed packages automatically remain in the system affecting the space and other tasks.

To perform this cleaning, we execute the following:

sudo apt autoremove

Install a specific version of an application using APT

By default in Linux, the most recent version available in the repository will be installed for an application, but at certain times we may not want to install the latest version and for that we can specify the version number. In this case it will be necessary to know the exact version number that you want to install.

sudo apt install <package_name>=<version>

In this way apt becomes one of the best alternatives for the administration and management of packages in Linux.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *