fbpx apt and apt-get Commands in Linux: Install, Update, Remove | Certificação Linux

Linux apt and apt-get Commands: Install, Update, and Remove Packages

📅 01/01/2019 ⏱ 5 min ✍️ Uira Ribeiro
Linuxcommands
Linux apt and apt-get Commands: Install, Update, and Remove Packages
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The apt-get command (Advanced Package Tool) is an advanced package manager for Linux of the Debian family, such as Debian itself, Debian, Ubuntu, Kali and Mint.

It can use local or remote files to install or update packages. This way it is possible to update the entire Debian system via ftp or http. This manager also keeps information about packages and their dependencies.

Due to its ease of operation, apt-get is the preferred method for handling packages. This utility offers dozens of options configured in the /etc/apt/apt.conf file.

The /etc/apt/sources.list file contains the locations where apt-get will find packages, the distribution to be verified (stable, testing, unstable, Woody, Sarge) and the section that will be copied (main, non-free, contrib, non-US).

Below a simple example of an /etc/apt/sources.list file with explanation of the sections:

deb http://www.debian.org/debian stable main contrib non-free
deb http://nonus.debian.org/debian-non-US stable non-US

In the /etc/apt/apt.conf file we can specify options that will modify the behavior of the apt-get program during package handling.

apt-get uses a package list to verify whether existing packages on the system need to be updated or not. The newest package list is copied through the apt-get update command.

apt-get is very useful, as the administrator does not need to manually download from the Internet the package they want to install, let alone deal with dependencies, as long as what they need is in the repositories indicated in the sources.list.

The most frequent options of this utility are:

  • -d: Downloads the files but does not install. It is useful for downloading large volumes of packages for later installation;
  • -s: Simulates the installation of packages but does not make modifications;
  • -y: Answers affirmatively to all questions asked during the installation/uninstallation process of packages.

The most frequent commands are:

  • dist-update: This command performs the automatic update of the Debian system;
  • install: This command installs a specific package specified by name;
  • remove: This command removes a specific package specified by name;
  • update: This command makes a list of all available packages. The process is done automatically before any modification to the packages;
  • upgrade: This command is used to perform a safe system upgrade, as it does not install packages that may cause conflicts or failures in the configuration files.

Examples:

# apt-get install airsnort

Installs the airsnort.x.y.deb package. This command accepts installing more than one package by separating names with spaces. You only need to specify the package name, without version (X), revision (Y) and suffix (.deb).

If necessary, apt-get will automatically install the dependencies required for the proper functioning of a package.

apt-get is also widely used to update all system packages, with the update command to update the databases with new packages and later the upgrade command to perform the updates:

# apt-get update
# apt-get upgrade

apt-get can update your entire distribution in an intelligent and safe way. It reads the list of available packages on the remote server, checks which are installed and their versions, and updates old packages.

# apt-get dist-update

But what about the apt command? How is it different?

Since 2014, Debian-based distributions have included an improvement of apt-get, which united and enhanced several tools that composed the apt-get package. This new fortified version of apt-get became known simply as apt.

apt does everything apt-get does. So, for installing, updating and removing packages on a daily basis, it does not matter if you use apt or apt-get.

To install one or more packages with apt:

# apt install pacote1 pacote2

To remove one or more packages:

# apt remove pacote1 pacote2

From time to time it is possible for one or more files that make up an installed package to be corrupted or accidentally removed. This way, the easiest way to recover these files is to reinstall the affected package.

Unfortunately, the packaging system may notice that the package is already installed and refuse to reinstall it. To work around the system and force a reinstallation of a package, you must use the --reinstall option of apt.

In the example the httpd package is reinstalled:

# apt --reinstall install httpd

To update installed packages with the latest version available in the repository, use the update command and then upgrade.

# apt update

Update downloads the updated package list.

To actually perform the upgrade:

# apt upgrade

The apt package manager keeps a copy of each downloaded .deb file in the /var/cache/apt/archives/ directory.

Over time, this directory can take up a lot of disk space. To empty the apt cache, use the clean command:

# apt clean

To switch from one major version of Debian or Ubuntu to the next, you need to use the apt full-upgrade command. With this instruction, apt will complete the upgrade, removing some obsolete packages and installing new dependencies:

# apt full-upgrade

Always before upgrading the system using a full-upgrade, make a backup. If you want to see how to update your Ubuntu, read this post.

Conclusion

If you use Debian or Ubuntu, it is essential to learn the apt command to manage packages on these systems.

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Liked it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp