Windows.  Viruses.  Notebooks.  Internet.  office.  Utilities.  Drivers

apt-get utility - productive free console program, used and working with the APT (Advanced Packaging Tool) library to install new software packages, remove existing ones, update installed ones, and also update the entire operating system.

The apt-cache console utility is used to search the cache for APT software packages. talking in simple words, this tool, is used to search for packages, gather information about packages, and find packages available for installation on operating systems based on Debian or Ubuntu.

How can I get a list of all available packages?

To see all available packages, run the following command:

apt-cache pkgnames

How can I find the package name and description.

To find the package name and description before installing, use the "search" flag. Using "search" with apt-cache will display a list of matching packages with brief description. For example, if you want to find the description of the vsftpd package: to do this, the command would be:

apt-cache search vsftpd

To find and list all packages whose name starts with vsftpd , you can use the following command:

apt-cache pkgnames vsftpd

How can I view package information?

For example, if you want to see information about a package, with a short description showing the version number, checksums, size, size after installation, categories, and so on, you can use the "show" subcommand, as shown below:

apt-cache show netcat

How can I check the dependencies of a package?

To check the dependencies of a particular package, you can use the showpkg subcommand to see if those dependencies are installed or not. For example, use the showpkg command along with the package name.

apt-cache showpkg vsftpd

How can I view cache statistics?

The stats subcommand will display full statistics about the cache, such as the total number of packages found in the cache. Use this command:

apt-cache stats

How to update the list of packages in the system?

The update command is used to synchronize and update package index files. Synchronization occurs with the sources specified in the file /etc/apt/sources.list. This command can be used, for example, to keep track of important package updates.

Sudo apt-get update

How to update packages in the system?

The upgrade command is used to upgrade everything installed on this moment software on your system. Sometimes it may happen that an update cannot be installed due to some other package that requires an older version.

sudo apt-get upgrade

But if you want to upgrade regardless of package requirements, use the dist-upgrade subcommand:

sudo apt-get dist-upgrade

How can I install or update any specific package?

The install subcommand is used to install or upgrade a package.

sudo apt-get install netcat

How can I install multiple packages at once?

You can enter the names of several packages to install them at the same time. For example, to install the nethogs and goaccess packages, you can run the following command:

sudo apt-get install nethogs goaccess

How to install multiple packages by "mask" name

With regular expressions, you can add multiple packages with special characters. For example, you can use an asterisk to install all packages that contain the string "name" in their name:

sudo apt-get install *name*

How to install packages without updating.

Using the --no-upgrade flag will prevent packages that are already installed from being upgraded.

sudo apt-get install packageName --no-upgrade

How to only update certain packages?

The --only-upgrade flag will not install new packages, it will only upgrade existing ones.

sudo apt-get install packagename --only-upgrade

How can I install specific version package?

Let's imagine that you need to install a specific version of a package, just use an equal sign along with the package name and attribute the desired version.

sudo apt-get install vsftpd=2.3.5-3ubuntu1

How to remove packages without deleting settings?

To delete software packages without removing their configuration files (for later use), use the remove command as shown.

sudo apt-get remove vsftpd

How to completely remove packages?

To remove a package along with its configuration files, use the purge subcommand as shown below.

sudo apt-get purge vsftpd

Or you can combine both commands, like this:

sudo apt-get remove --purge vsftpd

How can I clear disk space?

The clean command is used to free up disk space by removing the resulting package .deb files in your local repository.

sudo apt-get clean

How to download the source code of the package?

To only download the source code of a package, you can use the --download-only source option with the package name, like so:

sudo apt-get --download-only source vsftpd

How can I download and unpack a package?

To download and unpack the source code of a package into a special directory, run the following command:

sudo apt-get source vsftpd

How can I download, unpack and compile the source code of a package?

You can also download, unpack and compile the package source using the '--compile' option, as shown below:

sudo apt-get --compile source goaccess

How to download a package without installation

Using the "download" option, you can download any package without installing it. For example, the following command will only download the nethogs package to the current working directory.

sudo apt-get download nethogs

How can I view the changelog of a package?

The changelog flag downloads the package's changelog and displays the version of the package, if installed.

sudo apt-get changelog vsftpd

How can broken dependencies be fixed?

The "check" command is a diagnostic tool, it is used to update the package cache and check for broken dependencies.

Sudo apt-get check

How can I find and build dependencies?

The build-dep command looks for and installs the built dependencies of the required package. If the package is not in the local repository, you will get an error.

sudo apt-get build-dep netcat

How can I automatically clear the Apt-Get cache?

The autoclean command removes all .deb files from /var/cache/apt/archives to free up space on your hard drive.

sudo apt-get autoclean

How can I automatically remove unnecessary packages?

The autoremove subcommand is used to automatic removal packages that were installed as dependencies of others but are no longer needed. For example, the following command will remove an installed package along with its dependencies.

sudo apt-get autoremove vsftpd

Information courtesy of the site. Thank you.

APT (short for Advanced Packaging Tool) is a set of utilities for installing, uninstalling, upgrading, finding packages on Linux, and managing repositories. APT is also called a package manager.

APT uses package repositories. The list of repositories for APT is stored in a file /etc/apt/sources.list, as well as in the directory /etc/apt/sources.list.d/.

APT is used in distributions based on Dedian and Ubuntu.

There are various utilities for managing APT, but the most popular ones are the apt-get and apt command-line utilities.

In this article, we will look at how to use the apt command, and also learn how apt differs from apt-get.

What is the difference between apt and apt-get

To briefly answer a very popular question, what is the difference between apt and apt-get commands?

apt is a utility that appeared as an alternative to apt-get. It performs almost all the same functions as apt-get, but it is easier and clearer to work with.

For example, all apt commands have a simple syntax: apt commandname. And apt-get has additional commands, For example, apt-cache. Thus, when using apt, the user does not need to remember additional sets of commands.

In addition to simplifying work with commands, apt displays information more clearly, seemingly trifles, but it is more convenient to work with. For example, apt can show a progress bar, and when executed apt update you can see how many packages can be upgraded.

It is worth noting that the apt-get utility is more functional than apt. But for the average user, apt will be more than enough.

apt command

The syntax for the apt command is as follows:

sudo apt

Update package list

sudo apt update

APT has a list of repositories from which packages are installed. The list is stored in text file /etc/apt/sources.list, as well as in the directory /etc/apt/sources.list.d/. When executing the command apt update, APT iterates through the list of repositories and from each repository in the list gets information about the packages in the repository. All this information is stored in the system.

If a new version of a package is released, APT will not know about it until the command is executed apt update. Therefore, if you install this package (without first running apt update), then the version of the package that is stored in the system at the moment will be installed.

Do I need to run apt update before installing every package?

No, before installing each package apt update of course it shouldn't be done. It is enough to run apt update periodically. If you have more than one package to install, you can first run apt update and then install the packages.

Update installed packages

To update the packages installed on the system, use the command:

sudo apt upgrade

This command only updates packages to new versions, never removes or installs other packages.

There is another command to update packages:

Sudo apt full-upgrade

This command updates packages, and removes or installs new packages as needed to resolve dependencies.

Install package

To install the package use the command:

sudo apt install

Install multiple packages

To install multiple packages, their names are separated by a space:

sudo apt install

Install a specific package version

To install a specific package version, you need to specify the required version after the package name, through the equal sign:

sudo apt install=

Delete a package

To remove an installed package, use the command:

Sudo apt remove

Remove a package and its configuration files

sudo apt purge

apt-purge works similarly apt-remove, but also removes configuration files, related to the package. This means that if you installed some program, configured it, and then removed it with the command apt-remove, then the configuration file of this program will remain in the system. If you now install this program again, you will be able to use the previous configuration file, as it has not been removed.

apt-purge does not delete configuration files stored in your home directory.

If you removed the package with the command apt-remove, then you can do apt-purge for a given, already removed package, in order to “delete” its configuration files.

Remove unused packages

sudo apt autoremove

When you install a package, it often installs additional packages, which are its dependencies. If you now remove this package, then the dependencies will remain in the system. apt autoremove removes those dependencies, but only those that other installed packages don't need.

Package List

The apt list command is used to list packages based on some criteria.

List the packages installed on the system:

Apt list --installed

List packages that need to be updated (that have a newer version):

apt list --upgradable

List all packages available for your system:

Apt list --all-versions

Search for packages

apt search

This command searches for the specified words in the package name and in the package description. Regular expressions are supported.

You can only search by package names using the --names-only option:

Apt search --names-only

Searching for a package using regular expressions:

apt search --names-only "^python"

Package Information

apt show

Displays information about the package. The version, size, description, dependencies, and other information is displayed.

Editing the list of repositories

sudo apt edit-sources

Opens a file /etc/apt/sources.list V text editor for editing, after saving the changes and closing the editor, checks the file for errors. If there are errors, displays a suggestion for re-editing the file in order to correct the errors.

Table of analogues of apt and apt-get commands

Team
apt
Command analogue
apt-get
Description
apt installapt-get installInstall package
apt-removeapt-get removeDelete a package
apt-purgeapt-get-purgeRemove package and config files
apt autoremoveapt-get autoremoveRemove unused packages
apt updateapt-get updateUpdate package list
apt upgradeapt-get upgradeUpdate packages
apt full-upgradeapt-get dist-upgradeUpdate packages (remove and install new ones if required)
apt listApproximate analogue:
dpkg-query --list
Package List
apt searchapt-cache searchPackage Search
apt showapt cache showPackage Information

Sometimes there are situations when you need to find out which packages are installed on the system. This may be necessary if you want to backup installed packages, check their integrity, transfer all packages to another system and for many other tasks. On Debian, several methods can be used for this.

In today's article, we'll look at how to list installed Debian packages using the terminal, the curses interface, and the GUI. Such lists can be used not only for Reserve copy, but also to just iterate over and remove unnecessary programs, thereby clearing the system of debris.

The very first way to see installed Debian packages, this is the dpkg utility. It can be used not only in Debian, but in all distributions based on it:

dpkg --get-selections | grep -v deinstall

dpkg --get-selections | grep -v deinstall > mylist.txt

You can also remove all unnecessary information and keep only the package names:

dpkg -l | grep ^ii | awk "(print $2)" > mylist.txt

The next way to accomplish this task is to use the dpkg-query utility. It is similar to the previous version, but a little simpler. This command will list all installed packages along with information about them:

Here, too, you can only select package names with the -f option:

dpkg-query -f "$(binary:Package)\n" -W

The third method is the apt utility we are used to using to install applications, it has a list command:

apt list --installed

apt list --installed | grep python

We covered apt in more detail in the article. Another interesting feature of apt is to see which packages have been manually installed. To do this, type:

apt-mark showmanual

And another option using apt:

apt-cache pkgnames

The aptitude package management tool also allows you to list installed packages:

aptitude search "~i!~M"

Also, aptitude can run in curses mode, which is very convenient:

The last way to see the list of installed packages is in the /var/lib/apt/extended_states file. This is a database that contains installed programs debian in this format:

Package: package_name
Architecture: architecture
Auto-Installed: 0_or_1

cat /var/lib/apt/extended_states

Restoring the List of Installed Packages

Many users create a list of packages not just to look at, but for future recovery. If you made a list using dpkg, then it can be very easily restored to the system using a similar command:

sudo dpkg --clear-selections
$ sudo dpkg --set-selections< mylist.txt

Everything is very simple. To install packages after adding them to the list, use the command:

sudo apt dselect-upgrade

If you just have a list of package names, then you need to restore it a little differently. Just pass all these names to the apt command to install:

xargs< mylist.txt apt install -y

conclusions

In this article, we looked at how to list installed Debian packages. This can be very useful and is quite easy to do. I hope this information was helpful to you.

Due to the fact that some comrades do not understand what apt and dpkg are. Decided to create another post about these utilities.

APT and all, all, all. Exploring the capabilities of the APT package manager and related programs

Debian has brought a lot of positive innovations to the Linux world, many of which have been adopted by other distributions. Debian's most significant improvement was the APT package management system, after its release, all other distributions turned into obsolete junk. Today, APT is complex, smart, flexible, and hides many secrets from the uninitiated Linux user.

Advanced package management system

By itself, APT (Advanced Packaging Tool) is not a package management system in the truest sense of the word. All actions for unpacking, registering in the system and seeing the package database are performed by the dpkg package utilities, while the APT utilities are a wrapper with which you can search for packages, verify checksums, download from the repository, resolve dependencies, and a number of other actions. .

APT includes the following set of utilities:

apt package utilities

apt-cache - manipulates the cache of available packages, commonly used
to search for a package and/or get information about it

apt-cdrom - allows you to add a CD/DVD as a package source (repository)

apt-config - reads the values ​​of options given in the config
file /etc/apt/apt.conf, used by other APT utilities

apt-extracttemplates - Extracts DebConf config files
from packages, used by other APT utilities

apt-ftparchive - creates index files

apt-get - install, remove, update package list
and the packages themselves, the central APT utility

apt-key - manages the authentication keys used for verification
authenticity of package sources

apt-secure - verifies the digital signature of apt packages included
in the distribution and repositories

apt-sortpkgs - sorts index files

The utilities rely on the following configuration files:

APT Configuration Files

/etc/apt/sources.list - list of package sources (repositories)
/etc/apt/apt.conf - the main APT configuration file
/etc/apt/preferences - preference file, controls what version of the package will be
installed if there are several versions in the repository at once

APT is simple and straightforward to use, the average user usually needs only six commands below:

Basic APT Commands

apt-cache search mask - search for a package
apt-cache show package - view information about a package
apt-get install package - install a package
apt-get remove package - remove a package
apt-get update - update the cache of available packages
apt-get upgrade - upgrade all packages

The last two commands are usually executed one after the other, which will reinstall all packages for which new versions are available in the repository. If you need to update only the specified package, then after "apt-get update" you should run the command "apt-get install package".

The Ubuntu distribution makes the process of "talking" to APT utilities even easier and reduces it to clicking on the checkboxes. GUI. It has its own, extremely simple, package manager (it's called "Package Manager"), launched by cron "from the manager Update Manager, a graphical installer for manually downloaded GDebi deb packages, and a more powerful graphical add-on to Synaptic's APT utilities.

Meanwhile, APT is much more complex and flexible than it might seem at first glance. Therefore, in the following sections, we will consider several not quite typical methods of using it.

Third Party Package Sources

In addition to the head repository containing all packages from the distribution developers, there are many other package sources that may contain third-party software that is not available from the official repository, provide more recent versions of it, or simply be a faster mirror. The repository can be either a regular directory on your hard drive or a CD.

To teach APT to work with third-party repositories, it is enough to follow four simple steps:

The uri field is the address of the repository, which in most cases is an HTTP address, but can also be a link to a local repository (file:/root/repository), the address of a repository on an FTP or SSH server. The "distribution" field specifies the name of the distribution for which the packages are built. For Debian, the name can be one of stable, oldstable, unstable, testing, while in the case of Ubuntu, only the specific distribution name should be specified (for example, jaunty), and also various designations based on it (for example, jaunty-updates, jaunty-backports, jaunty-security). I must say that APT is not at all opposed to mixing packages from different distributions on the same system, but you will be responsible for the consequences in this case. The component is usually named main, contrib, or non-free on Debian and main, universe, multiverse, partner, and restricted on Ubuntu. These are all the names of different package repositories that are separated only to separate packages based on some criteria. For example, main are packages compiled by the Ubuntu / Debian development team, there are certain guarantees for the quality of the software contained in them, including timely updates and bug fixes, while contrib and universe are third-party software that you install at your own peril and risk.

2. Add to apt keyring the public key of the repository, used to verify its authenticity and reliability. The key can be obtained by any means and added by running the "apt-key add key" command, but this method is rarely practiced due to inconvenience. In the vast majority of cases, you will be dealing with a team

sudo apt-key adv --keyserver cert-server --recv-keys key-id
which requests the key directly from the certificate server (for Ubuntu, this is keyserver.ubuntu.com). This is how most 3rd party developers distribute their software for Debian/Ubuntu distributions (with the rest just posting packages and their checksums). For example, by going to the page of the project you are interested in hosted by launchpad.net and clicking on the link "Technical details about this PPA", you will see a line that needs to be added to /etc/apt/sources.list, the "Signing key:" will contain Key ID.

3. Refresh the cache of available packages:

sudo apt-get update
4. Install the package using the "apt-get install package" command.

Many developers put a link to the repository and its key ID directly in the deb package, so after downloading the package, installing it and running the "apt-get update && apt-get upgrade" command, the packages will be updated along with their counterparts listed in the sources.list. In particular, this is how opera browsers and alpha release of google chrome.

A CD-based repository is much easier to add to sources.list. There is a special apt-cdrom command for this. You simply insert the CD into the drive and run the command:

sudo apt-cdrom add

Tricks and unusual situations

APT is APT, it is convenient and simple, but sometimes you can't do without tricks, the most useful of which you will learn from this section.

1. By default, the "apt-get remove" command removes a package completely only if none of its files have been changed since installation, otherwise the changed files remain intact. Naturally, configuration files are almost always changed, so apt-get leaves behind a bunch of garbage that you have to clean up by hand. The "apt-get purge" command instead of "apt-get remove" solves this problem.

2. Fans of picking in the system, as well as system administrators whose servers have been hacked will most likely want to return the packets to the initial state in which they were before the manipulation. This command will help:

sudo apt-get install --reinstall package
3. Lower-level deb package management utilities (such as dselect and dpkg) maintain a special list of package states that can be used to control which packages should be installed or removed in batch mode (this is how the dselect + dpkg bundle works). It can also be used for many other purposes, such as transferring a system configuration to another machine. Run the following command:

dpkg --get-selections > file
Transfer the file to another machine and run two commands on it:

cat file > dpkg --set-selections
apt-get dselect-upgrade

All packages of the source system will be added to the system. To have the package state file also contain information about which packages to remove from the system, add a "\*" character after the "--get-selections" argument. The status list does not contain package versions, this can be used after installing more new version distribution kit to bring it to the required state.

4. You have manually patched a file of one of the system packages and do not want that package to be upgraded (wiping out all your changes) after calling "apt-get upgrade". In this case, the list of states will again come to your aid. A package can be "frozen", causing apt-get to refuse to update it and skip:

echo -e "coreutils hold" | dpkg --set-selections
You can force a package update by specifying the "-u" flag when calling apt-get.

5. Like any system with network functionality, APT allows you to use a proxy to access repositories. To enable this feature, add the following line to the /etc/apt/apt.conf file:

Acquire::http::Proxy "http://xxx.xxx.xx:yyyy"

Where xxx.xxx.xx is the name of your proxy, yyyy is the port.

6. APT utilities usually request the newest version of a package from all that are in its cache, so if you added various experimental and unstable repositories to sources.list, then after updating you will get a distribution kit consisting exclusively of experimental or unstable packages, and a bunch of problems caused by this state of affairs. However, the situation is easily resolved by placing the following line in /etc/apt/apt.conf:

APT::Default-Release "release";

Where release is oldstable, stable, unstable, testing, or experimental for Debian, or the release name for Ubuntu. Now, if you need to install a package from the specified distribution, just write its name after the "-t" argument when calling apt-get:

sudo apt-get -t unstable install package
7. All received apt-get deb packages are stored in the /var/cache/apt/archives directory, which means that if you reinstall the system, you can copy the contents of the directory to another disk/partition, and then restore it and save time/ package installation traffic. In addition, it is essentially a snapshot of your installed system(that part of it that you installed yourself), which can be attributed to a friend (along with the list of states described in the third paragraph) or, if not needed, removed to free up space.

8. The remote system snapshot described in the previous paragraph can be easily restored using the following construction:

sudo dpkg --get-selections | grep -v "deinstall" | \
awk "(print $1)" | xargs dpkg-repack

9. In addition to binary packages, the Debian/Ubuntu repositories also contain application source packages that can be obtained and built using the following command:

sudo apt-get -b source packagename

Third Party Utilities

The APT system has come a long way in development, so in addition to the official utilities included in the apt package, the Debian and Ubuntu repositories are replete with a lot of third-party utilities, which can be used to perform some non-standard tasks.
The most useful of them is called apt-file and is necessary, as you might guess from the name, to determine whether a particular file belongs to a particular package. Install:

sudo apt-get install apt-file
We ask apt-file to create a cache of all files installed in the package system (it will be searched for):

apt-file search /usr/bin/apt-get
apt: /usr/bin/apt-get

Request a list of all package files:

apt-file list apt

A simple apt-show-versions utility will show you which packages can be upgraded with versions and other information. Run it with the "-u" flag to get a list of only packages to upgrade (instead of a list of all packages).

If you installed a large number of various packages and now you want to get rid of unnecessary rubbish, then the deborphan utility will help in this matter, which searches for unused packages and orphaned dependencies. Just run deborphan with no arguments, and you will see a list of packages, which you can immediately pass as input to the “apt-get remove” command, or simply run this command:

sudo apt-get remove `deborphan`

By default, deborphan only processes packages that contain libraries, but this behavior can be changed by adding the "-a" flag to the command invocation:

You should not immediately rush to remove the packages shown by the utility, because even the most powerful heuristic algorithm is not able to determine your personal needs. So, the program showed me the google-chrome, inkscape and even xorg packages.

The apt-move utility will allow you to create a local repository. Install the program, open the /etc/apt-move.conf file, specify the path to the directory where the repository should be located in the LOCALDIR option, and run the command:

sudo apt-move update

As a result, all packages downloaded from the Web using apt-get (directory /var/cache/apt/archives) will be moved to the directory specified in the config, for which an index file will be created. This convenient way creating an intranet repository for those cases when a lot of identical packages need to be installed on many machines.

To create a local repository, it is also very convenient to use the apt-proxy server, which allows you to cache deb packages downloaded from the repository on the server side. To do this, apt-proxy is installed on a dedicated machine (perhaps a gateway), and the sources.list of clients is modified so that the address of this machine is specified as the uri field of all repositories. As a result, all requests for deb packages are redirected to apt-proxy, which requests the package from the head repository and stores it in its cache, and all subsequent requests for this package will be answered from the cache.

First, install apt-proxy on a dedicated machine:

sudo apt-get install apt-proxy

Next, open the /etc/apt-proxy/apt-proxy-v2.conf file, go to the section and replace the value of the address option with the IP address of the machine, and also describe the packet sources used by apt-proxy, for example:

sudo vi /etc/apt-proxy/apt-proxy-v2.conf


backends = http://en.archive.ubuntu.com/ubuntu/
min_refresh_delay = 1d


backends=http://security.ubuntu.com/ubuntu/
min_refresh_delay = 1d

Usually these two addresses are enough to cover the entire range of packages provided by the Ubuntu developers. Restart apt-proxy:

sudo invoke-rc.d apt-proxy restart

To switch clients to apt-proxy, we take the standard Ubuntu sources.list, replace all real uri fields with "http://ip-address-apt-proxy:9999/ubuntu/" and copy this file to each client.

There are many other, less interesting utilities that work in conjunction with APT. For example, apt-dater allows you to update packages on a large number of remote nodes using a pseudo-graphical interface. The aptsh program implements a sh-like command interface on top of the commands of the apt package, aptfs is the virtual file system for managing APT. The debdelta utility, which allows you to update packages by downloading their deltas from the Web, could be a topic for a separate article if there was at least one up-to-date repository for it.

Aptitude

The apt-get utility and its relatives are not the only implementation of APT available. An even more powerful, convenient and versatile alternative is called aptitude and is a concentrated functionality of apt-get, apt-cache and dselect in one place.
Aptitude allows you to install/uninstall, search, update, and do a lot of other things with packages using two types of interface: a command mode similar to apt-get and apt-cache, and a pseudo-graphical interface that looks like dselect but much more convenient. and functional.

In command line mode, aptitude can be used to do things like:

aptitude install - install a package

aptitude remove - Remove a package and orphaned dependencies

aptitude purge - remove package, orphaned dependencies
and the remaining configuration files after them

aptitude search - search for a package in the cache (list of available packages)

aptitude update - cache update

aptitude safe-upgrade - upgrade packages

aptitude clean - remove previously downloaded packages

aptitude full-upgrade - upgrade packages,
even if this action requires the removal of any packages

aptitude show - package information

aptitude autoclean - remove obsolete packages

aptitude hold - set a ban on updating a package

The interactive mode, available when you run aptitude with no arguments, allows you to perform all the same actions using a pseudo-graphical interface built on top of the ncurses library. It works in batch mode (selected packages - started the installation process), so it will be convenient in cases where you need to install a large number of packages.

Easter eggs

The developers of the APT utilities turned out to be guys with a slightly twisted sense of humor. What is the result of the following command:

sudo apt-get moo
What looks even wilder is what the creators of aptitude have built into their program. Try:

sudo aptitude moo
A kind of Easter egg easter egg. OK:

sudo aptitude -v moo
sudo aptitude -vv moo
sudo aptitude -vvv moo
sudo aptitude -vvvv moo
sudo aptitude -vvvvv moo

And the final chord:

sudo aptitude -vvvvvv moo

Useful apt-cache commands

apt-cache show package - detailed information about the package
apt-cache showpkg package - general information about the package
apt-cache depends package - list of package dependencies
apt-cache rdepends package - list of reverse dependencies (who needs said package)

APT Dictionary

Package - a program, library, sources or any other files, as well as their metadata, packaged in a specially formed archive.

Repository - a place where deb packages are stored.

Available packages cache (or simply cache) is a file that caches information about all packages available from the sources listed in /etc/apt/sources.list. The cache is updated every time the "apt-get update" command is called.

Index file - the head file of the repository containing the name, version, size, short and Full description and dependencies for each package. Named Packages.gz for a binary repository and Sources.gz for a source repository. Created using the pkg-scanpackages and dpkg-scansources utilities.

Apt keyring (literally: apt keyring) is a keystore that authenticates package sources (repositories).

What is inside?

The hallmark of Deb format packages is their simplicity. Any Deb package consists of three files: data.tar.gz, control.tar.gz and debian-binary, packed with the ar archiver. The data.tar.gz file is the contents of the package (binaries, man "s, documentation, etc.), control.tar.gz is metadata, in the simplest version, two files: control containing a description of the package, dependencies, size, etc. .d., and md5sums are the checksums of all files in the package.The debian-binary file contains the version of the Deb package format (e.g. 2.0) To unpack the package, you can use the command:

ar -xv package.deb && tar -xzf data.tar.gz

The Advanced Packaging Tool is a high level packaging tool.

Working with packages with dpkg

dpkg is the main program on the system for dealing with Debian packages. If there are .deb packages, it is dpkg that allows you to install them or parse their contents. However, this program has only a partial understanding of the Debian world: it knows what is installed on the system, as well as everything passed to it on the command line, but it knows nothing about other packages available. Therefore, it will fail if it finds an unsatisfied dependency. Tools like apt, on the other hand, will automatically create a list of dependencies to install everything as automatically as possible.

dpkg or apt?

dpkg should be considered as a low-level tool (engine) and apt as a more user-friendly tool that bypasses the limitations of the former. These tools work together, each with its own specifics, sharpened for a certain range of tasks.

Installing packages

dpkg is primarily a tool for installing already available Debian packages (because it doesn't download anything). To install a package, use the -i or --install option.

Installing a package with dpkg

dpkg -i man-db_2.7.0.2-5_amd64.deb




The man-db package (2.7.0.2-5) is being configured...

We can see every step that dpkg is running, so we know where some error might have occurred. Installation can also be done in two steps: unpacking first, then configuration. This makes apt-get make fewer calls to dpkg (each such call is an expensive operation due to the need to load the database into memory, including the entire list of already installed files).

Separate unpacking and setup

dpkg --unpack man-db_2.7.0.2-5_amd64.deb

(Reading database... 86425 files and directories currently installed.)
Preparing to unpack man-db_2.7.0.2-5_amd64.deb ...
Unpacks man-db (2.7.0.2-5) to replace (2.7.0.2-5) ...
Processing triggers for mime-support (3.58) ...

dpkg --configure man-db

The man-db package (2.7.0.2-5) is being configured...
Updating database of manual pages ...

Sometimes dpkg fails to install a package for one reason or another and returns an error; if the user instructs to ignore this error, only a warning will be issued; there are various --force-* options for this. The dpkg --force-help command, or the documentation for that command, will give you a complete list of these options. The most common mistake that you will have to face sooner or later is a file conflict. When a package contains a file that is already installed by another package, dpkg will refuse to install it and we will get this message:

The libgdm package is unpacked (from the file.../libgdm_3.8.3-2_amd64.deb) ...
dpkg: error processing /var/cache/apt/archives/libgdm_3.8.3-2_amd64.deb (--unpack) option:
trying to overwrite "/usr/bin/gdmflexiserver" which is already in the gdm3 3.4.1-9 package

In this case, if you think that replacing this file does not pose a significant threat to the stability of your system (it often does), you can use the --force-overwrite option, which will tell dpkg to ignore this error and overwrite the file.
While there are many --force-* options, only --force-overwrite is recommended for regular use. The rest are for exceptional cases only, and it's best not to touch them as long as possible in order to respect the rules laid down when the package was created. Do not forget that these rules are a guarantee of the integrity and stability of the system.

ATTENTION! Effective use of --force-*

If you're not careful, using the --force-* option can cause APT commands to stop working. Some of these options allow you to install a package with unmet dependencies or a conflict. As a result, the consistency of the system in terms of dependencies is broken, and the APT commands will refuse to perform any action other than those that return the system to a consistent state (this usually comes down to installing a missing dependency or removing a problematic package). Here is an example of a message indicating such an error, which is received after installing a new version of rdesktop, ignoring the dependency on the newer version of libc6:

apt full-upgrade

You may want to use "apt-get -f install" to fix these errors.
Packages with unmet dependencies:
rdesktop: Depends: libc6 (>= 2.5) but 2.3.6.ds1-13etch7 is already installed
E: Unmet dependencies.

Try using -f.
Intrepid administrators, confident in their analysis of the situation, can ignore the dependency or conflict warning by using the appropriate --force-* option. In this case, if you want to continue using apt or aptitude, you need to edit /var/lib/dpkg/status and remove/change the dependency or conflict.
Editing given file is a dirty hack and should not be used except in the most extreme cases. Often best solution is to rebuild the package that is causing the problem, "Rebuilding a package from its source code”) or using a newer version (possibly fixed) from a repository such as stable-backports (see Section 6.1.2.4, “Backward-Compatible Stable Software”).

Removing a package

Running dpkg with the -r or --remove option followed by a package name will remove that package. This removal, however, is not complete: all configuration files, maintainer scripts, log files (system logs), and other user data used by this package will remain. In this way, it is easy to get rid of the program by uninstalling it, but at the same time it remains possible to install it again with the same configuration. For complete removal anything related to a package, use the -P or --purge option, followed by the package name.

Complete removal of the debian-cd package

dpkg -r debian-cd

(Reading database... 97747 files and directories currently installed.)

dpkg -P debian-cd

(Reading database... 97401 files and directory currently installed.)
Removed debian-cd (3.1.17) package...
Cleaning up debian-cd (3.1.17) package configuration files...

dpkg database queries and parsing .deb files

For most options, there are "long" (one or more words preceded by a double hyphen) and "short" options (one letter, often the first letter of the "long" option, after a single hyphen). This convention is so common that it is already a POSIX standard.
Before wrapping up this section, let's look at the dpkg options for querying the internal database for various information. This will list the long options first, followed by the corresponding short options (which, of course, take the same arguments). Thus, --listfiles package (or -L) lists the files installed by the package; --search file (or -S) searches for the package this file belongs to; --status package (or -s) displays information about a particular installed package; --list (or -l) lists packages known to the system and their status; --contents file.deb (or -c) lists the files in this package; --info file.deb (or -I) displays information about a Debian package.

Getting information with dpkg

dpkg -L base-passwd

/.
/usr
/usr/sbin
/usr/sbin/update-passwd
/usr/share
/usr/share/man
/usr/share/man/ru
/usr/share/man/ru/man8
/usr/share/man/ru/man8/update-passwd.8.gz
/usr/share/man/pl
/usr/share/man/pl/man8
/usr/share/man/pl/man8/update-passwd.8.gz
/usr/share/man/man8
/usr/share/man/man8/update-passwd.8.gz
/usr/share/man/fr
/usr/share/man/fr/man8
/usr/share/man/fr/man8/update-passwd.8.gz
/usr/share/doc-base
/usr/share/doc-base/users-and-groups
/usr/share/base-passwd
/usr/share/base-passwd/passwd.master
/usr/share/base-passwd/group.master
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/base-passwd
/usr/share/doc
/usr/share/doc/base-passwd
/usr/share/doc/base-passwd/copyright
/usr/share/doc/base-passwd/users-and-groups.html
/usr/share/doc/base-passwd/changelog.gz
/usr/share/doc/base-passwd/users-and-groups.txt.gz
/usr/share/doc/base-passwd/README

dpkg -S /bin/date

coreutils: /bin/date

dpkg -s coreutils

Package: coreutils
Essential: yes
Status: install ok installed
Priority: required
Section: utilities
Installed-Size: 13822
Maintainer: Michael Stone
Architecture: amd64
Multi-Arch: foreign
Version: 8.13-3.5
Replaces: mktemp, timeout
Depends: dpkg (>= 1.15.4) | install info
Pre-Depends: libacl1 (>= 2.2.51-8), libattr1 (>= 1:2.4.46-8), libc6 (>= 2.7), libselinux1 (>= 1.32)
conflicts: timeout
Description: GNU core utilities
This package contains the basic file, shell and text manipulation
utilities which are expected to exist on every operating system.
.
Specifically, this package includes:
arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp
csplit cut date dd df dir dircolors dirname du echo env expand expr
factor false flock fmt fold groups head hostid id install join link ln
logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup nproc od
paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir runcon
sha*sum seq shred sleep sort split stat stty sum sync tac tail tee test
timeout touch tr true truncate tsort tty uname unexpand uniq unlink
users vdir wc who whoami yes
Homepage: http://gnu.org/software/coreutils

dpkg -l "b*"

Desired=unknown[u]/install[i]/remove[r]/clean[p]/fix[h]
| Status=not[n]/installed[i]/configured[c]/unpacked[U]/partially configured[F]/
partially set[H]/trig-aWait/Trig-pend
|/ Error?=(none)/reinstall required[R] (uppercase
in the status and error fields indicates an abnormal situation)
||/ Name Version Architecture Description
+++-============-==============-==============-================================
un backupninja<нет>(description not available)
base<нет>(description not available)
un base-config<нет>(description not available)
ii base-files 7.1 amd64 Debian base system miscellaneous
ii base-passwd 3.5.26 amd64 Debian base system master passwo
[...]

Dpkg -c /var/cache/apt/archives/gnupg_1.4.12-7_amd64.deb

drwxr-xr-x root/root 0 2013-01-02 19:28 ./
drwxr-xr-x root/root 0 2013-01-02 19:28 ./usr/
drwxr-xr-x root/root 0 2013-01-02 19:28 ./usr/share/
drwxr-xr-x root/root 0 2013-01-02 19:28 ./usr/share/doc/
drwxr-xr-x root/root 0 2013-01-02 19:28 ./usr/share/doc/gnupg/
-rw-r--r-- root/root 3258 2012-01-20 10:51 ./usr/share/doc/gnupg/TODO
-rw-r--r-- root/root 308 2011-12-02 18:34 ./usr/share/doc/gnupg/FAQ
-rw-r--r-- root/root 3543 2012-02-20 18:41 ./usr/share/doc/gnupg/Upgrading_From_PGP.txt
-rw-r--r-- root/root 690 2012-02-20 18:41 ./usr/share/doc/gnupg/README.Debian
-rw-r--r-- root/root 1418 2012-02-20 18:41 ./usr/share/doc/gnupg/TODO.Debian
[...]

Dpkg -I /var/cache/apt/archives/gnupg_1.4.12-7_amd64.deb

new debian package, version 2.0.
size 1952176 byte(s): control archive 3312 byte(s) long.
1449 bytes, 30 control lines
4521 bytes, 65 lines md5sums
479 bytes, 13 lines * postinst #!/bin/sh
473 bytes, 13 lines * preinst #!/bin/sh
Package: gnupg
Version: 1.4.12-7
Architecture: amd64
Maintainer: Debian GnuPG-Maintainers
Installed-Size: 4627
Depends: libbz2-1.0, libc6 (>= 2.4), libreadline6 (>= 6.0), libusb-0.1-4 (>= 2:0.1.12), zlib1g (>= 1:1.1.4), dpkg (>= 1.15.4) | install-info, gpgv
Recommends: libldap-2.4-2 (>= 2.4.7), gnupg-curl
Suggests: gnupg-doc, xloadimage | image magic | eog, libpcsclite1
Section: utilities
Priority: important
Multi-Arch: foreign
Homepage: http://www.gnupg.org
Description: GNU privacy guard - a free PGP replacement
GnuPG is GNU's tool for secure communication and data storage.
It can be used to encrypt data and to create digital signatures.
It includes an advanced key management facility and is compliant
with the proposed OpenPGP Internet standard as described in RFC 4880.
[...]

GOING FURTHER: Version Comparison

Since dpkg is a Debian packager, it contains, among other things, a reference implementation of the version number comparison logic. Therefore, it has the --compare-versions option, which is used external programs(mainly configuration scripts run by dpkg itself). This option requires three parameters: a version number, a comparison operator, and a second version number. Valid comparison operators are lt (strictly less than), le (less than or equal to), eq (equal to), ne (not equal to), ge (greater than or equal to), and gt (strictly greater than). If the comparison is true, dpkg returns 0 (success), if not, then a non-zero value (indication of an error).

$ dpkg --compare-versions 1.2-3 gt 1.1-4
$ echo $?
0
$ dpkg --compare-versions 1.2-3 lt 1.1-4
$ echo $?
1
$ dpkg --compare-versions 2.6.0pre3-1lt 2.6.0-1
$ echo $?
1

Note the unexpected failure of the last comparison: for dpkg, the letters pre, which usually denote a pre-release, have no special meaning, and alphabetic characters are compared in the same way as numbers (a< b < c ...), в алфавитном порядке. Именно поэтому dpkg считает, что «0pre3» больше, чем «0». При необходимости указать в номере версии, что она относится к предварительному выпуску, используется символ тильды «~»:

$ dpkg --compare-versions 2.6.0~pre3-1lt 2.6.0-1
$ echo $?
0

dpkg log file

dpkg keeps a log of all its actions in /var/log/dpkg.log. This log is extremely detailed, documenting every step in the processing of dpkg packages. This log not only helps track the behavior of dpkg, but also keeps a history of changes in the system: you can find the exact moment when each package was installed or updated, and this information can be extremely useful in finding out why the behavior of the system as a whole has changed. In addition, information about all versions is recorded and can be easily checked against the changelog.Debian.gz from the respective package or online bug reports.

Multi-architecture support

All Debian packages have an Architecture field in their metadata. This field can either contain the value "all" (for packages that are architecture independent) or the name of the specific architecture for which the package is intended (eg "amd64", "armhf", ...). In the latter case, dpkg will by default only allow a package to be installed if its architecture matches the system architecture returned by dpkg --print-architecture.
This restriction ensures that there are no binaries compiled for the wrong architecture on the system. That would be great, but on (some) computers it is possible to run binaries for different architectures, either natively (e.g. "amd64" systems run binaries for "i386") or through emulators.

Enabling Multiarchitecture

dpkg's multiarch support allows you to define "foreign architectures" that can be installed on a given system. This is easily done with dpkg --add-architecture, as shown in the example below. There is also a corresponding dpkg --remove-architecture command to disable support for a foreign architecture, but it can only be used when there is not a single package of this architecture left on the system.

dpkg --print-architecture
amd64

dpkg: error processing archive gcc-4.9-base_4.9.1-19_armhf.deb (--install):
package architecture (armhf) does not match system (amd64)
Errors were encountered while processing:
gcc-4.9-base_4.9.1-19_armhf.deb

dpkg --add-architecture armhf
dpkg --add-architecture armel
dpkg --print-foreign-architectures
armhf
armel

dpkg -i gcc-4.9-base_4.9.1-19_armhf.deb

Selecting previously unselected package gcc-4.9-base:armhf.
(Reading database ... 86425 files and directories currently installed.)
Preparing to unpack gcc-4.9-base_4.9.1-19_armhf.deb ...
Unpacking gcc-4.9-base:armhf (4.9.1-19) ...
Setting up gcc-4.9-base:armhf (4.9.1-19) ...

dpkg --remove-architecture armhf

dpkg: error: cannot remove architecture "armhf" currently in use by the database

dpkg --remove-architecture armel
dpkg --print-foreign-architectures
Multiarch support in APT

APT will automatically detect if dpkg is configured to support foreign architectures and will start downloading the appropriate Packages files during the upgrade process.
Foreign packages can be installed with apt install package:architecture.

Using proprietary i386 binaries on amd64 systems

There are a few cases where multi-architecture can come in handy, but the most common one is to make it possible to run 32-bit files (i386) on 64-bit systems (amd64), in particular because some popular proprietary applications (like Skype) are only available as 32-bit versions.

Multiarchitecture Changes

To make multi-arch support truly useful, the libraries needed to be repackaged by moving them to an architecture-specific directory so that multiple copies (for different architectures) could be installed at the same time. Such updated packages contain a "Multi-Arch: same" header indicating to the package management system that different package architectures can be installed together (and that these packages can only satisfy dependencies of packages of the same architecture). Since multiarch support was only added in Debian Wheezy, not all libraries have been converted yet.

dpkg -s gcc-4.9-base

dpkg-query: error: --status requires a valid package name, but 'gcc-4.9-base' is not: ambiguous package name 'gcc-4.9-base' with more than one instance installed

Use the --help option to display help on package requests.

Dpkg -s gcc-4.9-base:amd64 gcc-4.9-base:armhf | grep ^Multi

Multi-Arch: same
Multi-Arch: same

Dpkg -L libgcc1:amd64 |grep .so

/lib/x86_64-linux-gnu/libgcc_s.so.1

dpkg -S /usr/share/doc/gcc-4.9-base/copyright

gcc-4.9-base:amd64, gcc-4.9-base:armhf: /usr/share/doc/gcc-4.9-base/copyright

It is worth noting that packages with the Multi-Arch: same field should be named with the name of the architecture so that they can be uniquely identified. They may also have shared files with other instances of the same package; dpkg in this case ensures that all packages have bit-for-bit identical common files. All instances of a package must be of the same version, so they must be updated together.
Multi-architecture support also brings some interesting features to the dependency handling mechanism. To satisfy a dependency, either a package marked "Multi-Arch: foreign" or a package with the same architecture is required (for dependency resolution, architecture-independent packages are considered to have the same architecture as the system). A dependency can also be relaxed to allow a package of any architecture to satisfy it using the package:any syntax, but foreign packages can only satisfy such a dependency if they are marked "Multi-Arch: allowed".

Used materials.

Ubuntu 16.04 is out now and brings a lot of very interesting changes to its users such as support for file system BSD - ZFS support new technology package installations - snap and many others. But one thing you probably haven't heard of yet, because little things like that get lost a lot, is apt.

What is apt? This is a new package manager for Ubuntu ready to take on the job of apt-get. It was designed to be friendlier, more efficient and more secure. So what did Canonical have in mind when they introduced the new package manager? Are there really differences between apt vs apt-get? This is what we will find out in today's article.

Apt was implemented to make it easier to work with the package manager and to combine multiple commands into one. The functionality of apt-get has been redesigned to work correctly in apt.

Although these new commands are designed to work similarly to apt-get, they are based on new code to interact with packages.

The main reason for introducing apt is the very essence of Ubuntu - simplicity and ease of use. Whether people want to admit it or not, apt-get is an obsolete tool and its practicality is highly questionable. Apt has been designed from the ground up to be even more efficient and designed to be enjoyable for new users.

apt vs apt-get. What are the differences?

apt or apt-get. So what is the difference between these two solutions? For starters, you no longer need to use apt-get autoremove to clear the package cache. Also you don't need to type apt-cache search to find packages.

These commands have been replaced by apt search and apt remove. The main difference of apt is that it replaces all the commands apt-get, apt-cache, etc. All the functionality is combined in one utility.

Although this is not the only difference from apt-get. Software installation progress bars have been improved here. It also supports some additions that make the utility smarter than the previous one. For example, when updating software sources with apt-get, there is no easy way see the list of packages available for updating. You can just sudo apt-get update and then:

sudo apt list-upgradable

Of course, little things, but nice. New, modern output colors have also been added, and overall package installation is faster. Canonical is in no hurry to move away from apt-get, but they will make it a positive change.

New Apt Commands

Here is a list of commands supported by apt, taken directly from the --help output. These commands are very similar to the implementation of apt-get and apt-cache, but are more organized and grouped.

Basic commands:

  • list- package list
  • search- search for packages by name
  • show- show detailed information about the package
  • update- update lists of available packages
  • install- install the package
  • remove- remove package
  • upgrade- install available new package versions
  • full upgrade- complete system update
  • edit-sources- edit software sources file

For more information, run man apt in a terminal. The information stored there will help you thoroughly study the new utility.

conclusions

Apt-get is a tried and true part of a software manager. This tool has been around for a long time and comes by default in many releases of Ubuntu and Debian. We always used it when it was necessary to update something, update software or even just clean the system of garbage.

However, it is getting old. The package manager no longer meets all the needs of users, and therefore it is slowly being replaced by apt. Ubuntu developers understand that they need to update their package manager to make it simpler, more elegant, and more secure. But while both utilities exist in the system, it is up to you to choose whether to use apt or apt-get. Will you be using the new package manager? Or are you already using it?

If you notice an error, select a piece of text and press Ctrl + Enter
SHARE: