CentOS

apt command in Linux [Complete Guide]

apt is a useful command that stands for Advanced Package Tool and is used for installing, updating, removing, and overall managing deb packages on Ubuntu, Debian, and other Linux-based systems. The apt command is particularly useful as it allows an interactive way for users to update their system with the latest security patches, which makes it a very important Linux command.

In this article, we will take a closer look at the apt commands in Linux, and find out how you can use them even as a complete beginner.

Also read: Useful Apache commands to manage web service in Linux

What is apt?

Before we dig deep into the common syntax that apt has to offer, let us first look at what apt command does for you. apt is a free, user-centric software that works with the core libraries in Linux to offer an interactive way of installing and removing software. Where apt excels is the simplified process of handling the installation and removal of software in Linux-based systems. apt automates the entire process by precompiling source code and is considered an “important” priority in all current Debian releases.

Now, the apt command is not the only solution to manage your Linux installations as dpkg commands already exist that too can manage installations. However, the apt command is a more friendly way to find, install, upgrade and remove packages from a Linux-based system.

apt Command Syntax

Below is a common syntax of the apt command

apt [option] command [packages]

You can manage specific packages by including the name of the package in the command line. The apt command also supports different options to customize the process. Below are examples of some well-known apt arguments.

apt -d, --download-only

This command downloads a package only but does not proceed with the installation.

apt --no-download

Does not download any new package and instead install packages already installed.

apt -f, --fix-broken

There may be several dependencies when managing packages. The command above tries to fix broken dependencies.

apt -s, --simulate

This command shows what the output will be without altering the system.

apt -h, --help

When you are ever in doubt, pull up the help section, and an array of useful commands will pop up on the screen.

Most Common apt Commands

The apt tool works with several commands which will be difficult to list in this article. However, here are some of the most used apt commands that you will inevitably come across while using a Linux system.

sudo apt update

One of the most used commands which is used to get the latest versions of available packages, but not install the updates.

sudo apt upgrade

Similar to the update command, the upgrade command downloads and installs packages to the new version.

sudo apt full-upgrade

Upgrade installed packages and remove any pre-installed packages that are no longer necessary.

apt install

Installs a specified package.

apt remove

Remove any specific packages.

apt search

Search specific packages when a name is provided in the description.

Useful tips and tricks when using the apt command

Now that we have looked into some common apt commands, let us look at some of the common usages of the apt command.

Upgrade Packages with apt upgrade

We have previously seen an update and upgrade command using which we can install new packages. However, if you want to upgrade specific packages, appending its name at the end is a handy little trick.

sudo apt upgrade lsof

The update and upgrade command also prints the output when executed. But you can run these commands in just one step and avoid any confirmation pop-up by appending -y attribute at the end.

sudo apt update && sudo apt upgrade -y

List Packages using the apt list

The apt list is a command which is used to print the name and details of all available packages. However, the list can often be extremely big resulting in difficulty navigating between the list. This is where more attributes come in handy. For instance, you can type in

apt list | more

To move through the terminal page one at a time.

Conclusion

The apt command is a useful command which simplifies many of the tedious parts of managing packages in a Linux system. While it is often impossible to list all the things you can do with the apt command, our guide serves as a starting point that will guide you to speed with the apt command. You can learn more about the tips and tricks in Linux by clicking here.

Similar Posts