Linux установка пакетов apt

Using APT to Manage Packages in Debian and Ubuntu

Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

Advanced Package Tool, more commonly known as APT, is a package management system for Ubuntu, Debian, Kali Linux, and other Debian-based Linux distributions. It acts as a front-end to the lower-level dpkg package manager, which is used for installing, managing, and providing information on .deb packages. In addition to these functions, APT interfaces with repositories to obtain packages and also provides very efficient dependency management.

Most distributions that use APT also include a collection of command-line tools that can be used to interface with APT. These tools include apt-get , apt-cache , and the newer apt , which essentially combines both of the previous tools with some modified functionality. Other package managers and tools also exist for interacting with APT or dpkg. A popular one is called Aptitude. Aptitude includes both a command-line interface as well as an interactive user interface. While it does offer advanced functionality, it is not commonly installed by default and is not covered in this guide.

This guide aims to walk you through using APT and its command-line tools to perform common functions related to package management. The commands and examples used throughout this guide default to using the apt command. Many of the commands interchangeable with either apt-get or apt-cache , though there may be breaking differences.

Before You Begin

Before running the commands within this guide, you will need:

  1. A system running on Debian or Ubuntu. Other Linux distributions that employ the APT package manager can also be used. Review the Creating a Compute Instance guide if you do not yet have a compatible system.
  2. Login credentials to the system for either the root user (not recommended) or a standard user account (belonging to the sudo group) and the ability to access the system through SSH or Lish. Review the Setting Up and Securing a Compute Instance guide for assistance on creating and securing a standard user account.

Some commands in this guide require elevated privileges and are prefixed with the sudo command. If you are logged in as the root use (not recommended), you can omit the sudo prefix if desired. If you’re not familiar with the sudo command, see the Linux Users and Groups guide.

Читайте также:  Разрешения для папки линукс

What’s the difference between apt and apt-get / apt-cache ?

While there are more similarities than differences, there are a few important points to consider when decided which command to use.

  • apt : A newer end-user tool that consolidates the functionality of both apt-get and apt-cache . Compared to the others, the apt tool is more straightforward and user-friendly. It also has some extra features, such as a status bar and the ability to list packages. Both Ubuntu and Debian recommend the apt command over apt-get and apt-cache . See apt Ubuntu man pages
  • apt-get and apt-cache : The apt-get command manages the installation, upgrades, and removal of packages (and their dependencies). The apt-cache command is used to search for packages and retrieve details about a package. Updates to these commands are designed to never introduce breaking changes, even at the expense of the user experience. The output works well for machine readability and these commands are best limited to use within scripts. See apt-get Ubuntu man pages and apt-cache Ubuntu man pages.

In short, apt is a single tool that encompasses most of the functionality of other APT-specific tooling. It is designed primarily for interacting with APT as an end-user and its default functionality may change to include new features or best practices. If you prefer not to risk breaking compatibility and/or prefer to interact with plainer output, apt-get and apt-cache can be used instead, though the exact commands may vary.

Installing Packages

Installs the specified package and all required dependencies. Replace [package] with the name of the package you wish to install. The apt install command is interchangeable with apt-get install .

Before installing packages, it’s highly recommended to obtain updated package version and dependency information and upgrade packages and dependencies to those latest version. See Updating Package Information and Upgrading Packages for more details. These actions can be performed quickly by running the following sequence of commands:

sudo apt update && sudo apt upgrade 

Additional options, commands, and notes:

    Install a specific version by adding an equal sign after the package, followed by the version number you’d like to install.

sudo apt install [package]=[version] 
sudo apt reinstall [package] 

Updating Package Information

Downloads package information from all the sources/repositories configured on your system (within /etc/apt/sources.list ). This command obtains details about the latest version for all available packages as well as their dependencies. It should be the first step before installing or upgrading packages on your system.

Читайте также:  Сменить права доступа файла linux

This command is equivalent to apt-get update .

Upgrading Packages

Upgrades all packages to their latest versions, including upgrading existing dependencies and installing new ones. It’s important to note that the currently installed versions are not removed and will remain on your system.

This command is equivalent to apt-get upgrade —with-new-pkgs . Without the —with-new-pkgs option, the apt-get upgrade command only upgrades existing packages/dependencies and ignores any packages that require new dependencies to be installed.

Before upgrading packages, it’s highly recommended to obtain updated package version and dependency information. See Updating Package Information for more details. These two actions can be performed together through the following sequence of commands:

sudo apt update && sudo apt upgrade 

Additional options, commands, and notes:

    To view a list of all available upgrades, use the list command with the —upgradable option.

sudo apt install --only-upgrade [package] 

Uninstalling Packages

Removes the specified package from the system, but retains any packages that were installed to satisfy dependencies as well as some configuration files. Replace [package] with the name of the package you’d like to remove.

To remove the package as well as any configuration files, run the following command. This can also be used to just remove configuration files for previously removed packages.

Both of these commands are equivalent to apt-get remove and apt-get purge , respectively.

    To remove any unused dependencies, run apt autoremove ( apt-get autoremove ). This is commonly done after uninstalling a package or after upgrading packages and can sometimes help in reducing disk space (and clutter).

Common Command Options

The following options are available for most of the commands discussed on this guide.

    Multiple packages can be taken action on together by delimiting them with a space. For example:

sudo apt install [package1] [package2] 
sudo apt install [package] -y 

Listing Packages

The apt list command lists all available, installed, or upgradeable packages. This can be incredibly useful for locating specific packages — especially when combined with grep or less. There is no direct equivalent command within apt-cache.

    List all packages that are installed

Additional options, commands, and notes:

    Use grep to quickly search through the list for specific package names or other strings. Replace [string] with the package name or other term you wish to search for.

apt list --installed | grep [string] 

Searching for Available Packages

Searches through all available packages for the specified term or regex string.

Читайте также:  Handling interrupts in linux

The command apt-cache search is similar, though the output for apt search is more user-friendly.

Additional options, commands, and notes:

    Use the —full option to see the full description/summary for each package.

apt search [string1] [string2] 

Viewing Information About Packages

Displays information about an installed or available package. The following command is similar to apt-cache show —no-all-versions [package] .

The information in the output includes:

  • Package: The name of the package.
  • Version: The version of the package.
  • Installed-Size: The amount of space this package consumes on the disk, not including any dependencies.
  • Depends: A list of dependencies.
  • APT-Manual-Installed: Designates if the package was manually installed or automatically installed (for instance, like as a dependency for another package). This is visible within apt (not apt-cache ).
  • APT-Sources: The repository where the package information was stored. This is visible within apt (not apt-cache ).
  • Description: A long description of the package.

Adding Repositories

A repository is a collection of packages (typically for a specific Linux distribution and version) that are stored on a remote system. This enables software distributors to store a package (including new versions) in one place and enable users to quickly install that package onto their system. In most cases, we obtain packages from a repository — as opposed to manually downloading package files.

Information about repositories that are configured on your system are stored within /etc/apt/sources.list or the directory /etc/apt/sources.list.d/ . Repositories can be added manually by editing (or adding) a sources.list configuration file, though most repositories also require adding the GPG public key to APT’s keyring. To automate this process, it’s recommended to use the add-apt-repository utility.

sudo add-apt-repository [repository] 

Replace [repository] with the url to the repository or, in the case of a PPA (Personal Package Archive), the reference to that PPA.

Once a repository has been added, you can update your package list and install the package. See Updating Package Information and Installing Packages.

Cloning Packages to Another System

If you wish to replicate the currently installed packages to another system without actually copying over any other data, consider using the apt-clone utility. This software is compatible with Debian-based systems and is available through Ubuntu’s official repository.

sudo apt install apt-clone 
sudo apt-clone restore [name].apt-clone.tar.gz

This page was originally published on Thursday, May 12, 2022.

Источник

Оцените статью
Adblock
detector