- Как очистить apt cache и освободить дисковое пространство
- Что такое apt cache?
- Зачем сохранять кеш после установки пакета?
- Стоит ли очищать apt cache?
- Как правильно очистить apt cache?
- Безопасно ли удалять apt cache?
- How to Use apt-cache Command in Debian, Ubuntu and Other Linux Distributions
- What is apt-cache command used for?
- Using apt-cache command
- Search for packages
- Get detailed package information
- apt-cache policy
- Check dependencies and reverse dependencies of a package
- Check unmet dependencies
- apt-cache(8) — Linux man page
- Synopsis
- Description
- Commands
- 25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management
- 1. How Do I List All Available Packages?
- 2. How Do I Find Out Package Name and Description of Software?
- 3. How Do I Check Package Information?
- 4. How Do I Check Dependencies for Specific Packages?
- 5. How Do I Check statistics of Cache
- 6. How to Update System Packages
- 7. How to Upgrade Software Packages
- 8. How Do I Install or Upgrade Specific Packages?
- 9. How I can Install Multiple Packages?
- 10. How to Install Several Packages using Wildcard
- 11. How to install Packages without Upgrading
- 12. How to Upgrade Only Specific Packages
- 13. How Do I Install Specific Package Version?
- 14. How Do I Remove Packages Without Configuration
- 15. How Do I Completely Remove Packages
- 16. How I Can Clean Up Disk Space
- 17. How Do I Download Only Source Code of Package
- 18. How Can I Download and Unpack a Package
- 19. How Can I Download, Unpack and Compile a Package
- 20. How Do I Download a Package Without Installing
- 21. How Do I Check Change Log of Package?
- 22. How Do I Check Broken Dependencies?
- 23. How Do I Search and Build Dependencies?
- 24. How I Can Auto clean Apt-Get Cache?
- 25. How I Can Auto remove Installed Packages?
- If You Appreciate What We Do Here On TecMint, You Should Consider:
Как очистить apt cache и освободить дисковое пространство
Как очистить кеш apt? Мы просто используем параметр clean команды apt-get:
Но очистка кеша apt — это не просто выполнение указанной выше команды.
В этом руководстве выясним, что такое apt cache, почему он используется, почему вы хотите его очистить и что еще следует знать об очистке apt cache.
Для примера используем Ubuntu, но т.к речь идет об apt, данная информация применима к другим дистрибутивам на основе Debian и Ubuntu, таким как Linux Mint, Deepin и др.
Что такое apt cache?
Когда вы устанавливаете пакет с помощью команды apt-get или apt (или пакетов DEB в центре программного обеспечения), менеджер пакетов apt загружает пакет и его зависимости в формате .deb и сохраняет его в папке /var/cache/apt/archives
Во время загрузки apt хранит пакет deb в каталоге /var/cache/apt/archives/partial. Когда пакет deb загружен полностью, он перемещается в каталог /var/cache/apt/archives.
После загрузки файлов требуемого deb пакета и его зависимостей ваша система устанавливает данный пакет. Вот для чего нужен кеш. Системе необходимо место для хранения файлов пакетов перед их установкой.
Зачем сохранять кеш после установки пакета?
Загруженные файлы deb не удаляются из каталога сразу после завершения установки. Если вы удалите пакет и переустановите его, ваша система будет искать пакет в кеше и получать его отсюда, а не загружать его снова (если версия пакета в кеше такая же, как и версия в удаленном репозитории).
Это намного быстрее. Вы можете попробовать это самостоятельно и посмотреть, сколько времени потребуется программе для первой установки, удаления и повторной установки. Вы можете использовать команду time, чтобы узнать, сколько времени требуется для выполнения команды:
Стоит ли очищать apt cache?
Если у вас заканчивается дисковое пространство в корневом каталоге, вы можете очистить apt кеш. Это один из нескольких способов освободить дисковое пространство в Ubuntu.
Проверьте, сколько места занимает кеш, с помощью команды du:
Как правильно очистить apt cache?
Если вы хотите очистить кеш apt, воспользуйтесь специальной командой. Не удаляйте каталог кеша вручную.
Используйте команду apt-get с аргументом clean:
Данная команда удалит содержимое каталога /var/cache/apt/archives (кроме файла блокировки).
Есть еще одна команда, которая занимается очисткой кеша apt:
В отличие от clean, autoclean удаляет только те пакеты, которые невозможно загрузить из репозиториев.
Предположим, вы установили пакет xyz. Его файлы deb остаются в кеше. Если теперь в репозитории доступна новая версия пакета xyz, этот существующий пакет xyz в кэше теперь устарел и бесполезен. Опция autoclean удалит такие бесполезные пакеты, которые больше нельзя загрузить.
Безопасно ли удалять apt cache?
Очистка кеша не повлияет отрицательно на производительность системы. Возможно, если вы переустановите пакет, загрузка займет немного больше времени, но это все.
Опять же, используйте команду apt-get clean. Это быстрее и проще, чем вручную удалить каталог кеша.
Источник
How to Use apt-cache Command in Debian, Ubuntu and Other Linux Distributions
Last updated October 29, 2020 By Abhishek Prakash 2 Comments
With apt-cache command, you can search for package details in the local APT cache. Learn to use apt-cache command in this tutorial.
What is apt-cache command used for?
The apt package manager works on a local cache of package metadata. The metadata usually consists information like package name, version, description, dependencies, its repository and developers. With the apt-cache command, you can query this local APT cache and get relevant information.
You can search for the availability of a package, its version number, its dependencies among other things. I’ll show you how to use the apt-cache command with examples.
The location of APT cache is /var/lib/apt/lists/ directory. Which repository metadata to cache depends on the repositories added in your source list in the /etc/apt/sources.list file and additional repository files located in ls /etc/apt/sources.list.d directory.
Surprisingly, apt-cache doesn’t clear the APT cache. For that you’ll have to use the apt-get clean command.
Needless to say, the APT packaging system is used on Debian and Debian-based Linux distributions like Ubuntu, Linux Mint, elementary OS etc. You cannot use it on Arch or Fedora.
Using apt-cache command
Like any other Linux command, there are several options available with apt-cache and you can always refer to its man page to read about them.
However, you probably won’t need to use all of them. This is why I am going to show you only the most common and useful examples of the apt-cache command in this tutorial.
It is always a good idea to update the local APT cache to sync it with the remote repositories. How do you do that? You use the command:
sudo apt update
Search for packages
The most common use of apt-cache command is for finding package. You can use a regex pattern to search for a package in the local APT cache.
By default, it looks for the search term in both the name and description of the package. It shows the matching package along with its short description in alphabetical order.
You can narrow down your search to look for the search term in package names only.
If you want complete details of all the matched packages, you may use the —full flag. It can also be used with —names-only flag.
Get detailed package information
If you know the exact package name (or if you have manged to find it with the search), you can get the detailed metadata information on the package.
You can see all kind of details in the package metadata like name, version, developer, maintainer, repository, short and long description, package size and even checksum.
There is another option showpkg that displays information about the package name, version and its forward and reverse dependencies.
apt-cache policy
This is one of the rarely used option of apt-cache command. The policy options helps you debug the issue related to the preference file.
If you specify the package name, it will show whether the package is installed, which version is available from which repository and its priority.
By default, each installed package version has a priority of 100 and a non-installed package has a priority of 500. The same package may have more than one version with a different priority. APT installs the version with higher priority unless the installed version is newer.
If this doesn’t make sense, it’s okay. It will be extremely rare for a regular Linux user to dwell this deep into package management.
Check dependencies and reverse dependencies of a package
You can check the dependencies of a package before (or even after) installing it. It also shows all the possible packages that can fulfill the dependency.
You may also check which packages are dependent on a certain package by checking the reverse dependencies with apt-cahce.
Frankly, I was also surprised to see that a DevOps tool like Ansible has a dependency on a funny Linux command like Cowsay. I think it’s perhaps because after installing Ansible, it displays some message on the nodes.
Check unmet dependencies
You may get troubled with unmet dependencies issue in Ubuntu or other Linux. The apt-cache command provides option to check all the unmet dependencies of various available packages on your system.
Apt Cache Unmet
Conclusion
You can list all available packages with the apt-cache command. The output would be huge, so I suggest combining it with wc command to get a total number of available packages like this:
Did you notice that you don’t need to be root user for using apt-cache command?
The newer apt command has a few options available to match the features of apt-cache command. Since apt is new, apt-get and its associated commands like apt-cache are still preferred to be used in scripts.
I hope you find this tutorial helpful. If you have questions about any point discussed above or suggestion to improve it, please let me know in the comments.
Like what you read? Please share it with others.
Источник
apt-cache(8) — Linux man page
Synopsis
Description
apt-cache performs a variety of operations on APT’s package cache. apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata.
Commands
Unless the -h, or —help option is given, one of the commands below must be present. add file(s) Adds the named package index file(s) to the package cache. This is for debugging only. gencaches Performs the same operation as apt-get check. It builds the source and package caches from the sources in sources.list(5) and from /var/lib/rpm/. showpkg pkg(s) Displays information about the packages listed on the command-line. Remaining arguments are package names. The available versions and reverse dependencies of each package specified are listed, as well as forward dependencies for each version. Forward (normal) dependencies are those packages upon which the package in question depends; reverse dependencies are those packages that depend upon the package in question. Thus, forward dependencies must be satisfied for a package, but reverse dependencies need not be. For instance, apt-cache showpkg libreadline2 would produce output similar to the following:
Package: libreadline2Versions: 2.1-12(/var/lib/apt/lists/foo_Packages),Reverse Depends: libreadlineg2,libreadline2 libreadline2-altdev,libreadline2Dependencies:2.1-12 — libc5 (2 5.4.0-0) ncurses3.0 (0 (null))Provides:2.1-12 — Reverse Provides: Thus it may be seen that libreadline2, version 2.1-12, depends on libc5 and ncurses3.0 which must be installed for libreadline2 to work. In turn, libreadlineg2 and libreadline2-altdev depend on libreadline2. If libreadline2 is installed, libc5 and ncurses3.0 (and ldso) must also be installed; libreadlineg2 and libreadline2-altdev do not have to be installed. For the specific meaning of the remainder of the output it is best to consult the apt source code. stats Displays some statistics about the cache. No further arguments are expected. Statistics reported are:
- Total package names is the number of package names found in the cache.
- Normal packages is the number of regular, ordinary package names; these are packages that bear a one-to-one correspondence between their names and the names used by other packages for them in dependencies. The majority of packages fall into this category.
- Pure virtual packages is the number of packages that exist only as a virtual package name; that is, packages only «provide» the virtual package name, and no package actually uses the name. For instance, «mail-transport-agent» in the Debian GNU/Linux system is a pure virtual package; several packages provide «mail-transport-agent», but there is no package named «mail-transport-agent».
- Single virtual packages is the number of packages with only one package providing a particular virtual package. For example, in the Debian GNU/Linux system, «X11-text-viewer» is a virtual package, but only one package, xless, provides «X11-text-viewer».
- Mixed virtual packages is the number of packages that either provide a particular virtual package or have the virtual package name as the package name. For instance, in the Debian GNU/Linux system, «debconf» is both an actual package, and provided by the debconf-tiny package.
- Missing is the number of package names that were referenced in a dependency but were not provided by any package. Missing packages may be in evidence if a full distribution is not accessed, or if a package (real or virtual) has been dropped from the distribution. Usually they are referenced from Conflicts statements.
- Total distinct versions is the number of package versions found in the cache; this value is therefore at least equal to the number of total package names. If more than one distribution (both «stable» and «unstable», for instance), is being accessed, this value can be considerably larger than the number of total package names.
- Total dependencies is the number of dependency relationships claimed by all of the packages in the cache.
Источник
25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management
This article explains how quickly you can learn to install, remove, update and search software packages using apt-get and apt-cache commands from the command line. This article provides some useful commands that will help you to handle package management in Debian/Ubuntu based systems.
APT-GET and APT-CACHE Commands
What is apt-get?
The apt-get utility is a powerful and free package management command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages, removing existing software packages, upgrading of existing software packages and even used to upgrading the entire operating system.
What is apt-cache?
The apt-cache command line tool is used for searching apt software package cache. In simple words, this tool is used to search software packages, collects information of packages and also used to search for what available packages are ready for installation on Debian or Ubuntu based systems.
1. How Do I List All Available Packages?
To list all the available packages, type the following command.
2. How Do I Find Out Package Name and Description of Software?
To find out the package name and with it description before installing, use the ‘search‘ flag. Using “search” with apt-cache will display a list of matched packages with short description. Let’s say you would like to find out description of package ‘vsftpd‘, then command would be.
To find and list down all the packages starting with ‘vsftpd‘, you could use the following command.
3. How Do I Check Package Information?
For example, if you would like to check information of package along with it short description say (version number, check sums, size, installed size, category etc). Use ‘show‘ sub command as shown below.
4. How Do I Check Dependencies for Specific Packages?
Use the ‘showpkg‘ sub command to check the dependencies for particular software packages. whether those dependencies packages are installed or not. For example, use the ‘showpkg‘ command along with package-name.
5. How Do I Check statistics of Cache
The ‘stats‘ sub command will display overall statistics about the cache. For example, the following command will display Total package names is the number of packages have found in the cache.
6. How to Update System Packages
The ‘update‘ command is used to resynchronize the package index files from the their sources specified in /etc/apt/sources.list file. The update command fetched the packages from their locations and update the packages to newer version.
7. How to Upgrade Software Packages
The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages which are not already installed neither retrieved and installed to satisfy upgrade dependencies.
However, if you want to upgrade, unconcerned of whether software packages will be added or removed to fulfill dependencies, use the ‘dist-upgrade‘ sub command.
8. How Do I Install or Upgrade Specific Packages?
The ‘install‘ sub command is tracked by one or more packages wish for installation or upgrading.
9. How I can Install Multiple Packages?
You can add more than one package name along with the command in order to install multiple packages at the same time. For example, the following command will install packages ‘nethogs‘ and ‘goaccess‘.
10. How to Install Several Packages using Wildcard
With the help of regular expression you can add several packages with one string. For example, we use * wildcard to install several packages that contains the ‘*name*‘ string, name would be ‘package-name’.
11. How to install Packages without Upgrading
Using sub ‘–no-upgrade‘ command will prevent already installed packages from upgrading.
12. How to Upgrade Only Specific Packages
The ‘–only-upgrade‘ command do not install new packages but it only upgrade the already installed packages and disables new installation of packages.
13. How Do I Install Specific Package Version?
Let’s say you wish to install only specific version of packages, simply use the ‘=‘ with the package-name and append desired version.
14. How Do I Remove Packages Without Configuration
To un-install software packages without removing their configuration files (for later re-use the same configuration). Use the ‘remove‘ command as shown.
15. How Do I Completely Remove Packages
To remove software packages including their configuration files, use the ‘purge‘ sub command as shown below.
Alternatively, you can combine both the commands together as shown below.
16. How I Can Clean Up Disk Space
The ‘clean‘ command is used to free up the disk space by cleaning retrieved (downloaded) .deb files (packages) from the local repository.
17. How Do I Download Only Source Code of Package
To download only source code of particular package, use the option ‘–download-only source‘ with ‘package-name’ as shown.
18. How Can I Download and Unpack a Package
To download and unpack source code of a package to a specific directory, type the following command.
19. How Can I Download, Unpack and Compile a Package
You can also download, unpack and compile the source code at the same time, using option ‘–compile‘ as shown below.
20. How Do I Download a Package Without Installing
Using ‘download‘ option, you can download any given package without installing it. For example, the following command will only download ‘nethogs‘ package to current working directory.
21. How Do I Check Change Log of Package?
The ‘changelog‘ flag downloads a package change-log and shows the package version that is installed.
22. How Do I Check Broken Dependencies?
The ‘check‘ command is a diagnostic tool. It used to update package cache and checks for broken dependencies.
23. How Do I Search and Build Dependencies?
This ‘build-dep‘ command searches the local repositories in the system and install the build dependencies for package. If the package does not exists in the local repository it will return an error code.
24. How I Can Auto clean Apt-Get Cache?
The ‘autoclean‘ command deletes all .deb files from /var/cache/apt/archives to free-up significant volume of disk space.
25. How I Can Auto remove Installed Packages?
The ‘autoremove‘ sub command is used to auto remove packages that were certainly installed to satisfy dependencies for other packages and but they were now no longer required. For example, the following command will remove an installed package with its dependencies.
I’ve covered most of the available options with apt-get and apt-cache commands, but still there are more options available, you can check them out using ‘man apt-get‘ or ‘man apt-cache‘ from the terminal. I hope you enjoyed reading this article, If I’ve missed anything and you would like me to add to the list. Please feel free to mention in the comment below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник