- Глава 8. Инструменты управления пакетами Debian
- 8.1. Какие программы для управления пакетами имеются в Debian?
- 8.1.1. dpkg
- 8.1.2. APT
- How to Update Debian from Terminal
- Keeping Debian up-to-date
- Updating Debian
- Checking for updates
- Upgrading packages
- Updating APT cache and upgrading packages simultaneously
- Automating Debian update
- Final thoughts
- About the author
- Sidratul Muntaha
Глава 8. Инструменты управления пакетами Debian
8.1. Какие программы для управления пакетами имеются в Debian?
В Debian для управления пакетами имеется множество средств, от программ с графическими или текстовыми интерфейсами, до низкоуровневых утилит установки пакетов. Корректная работа всех доступных инструментов зависит от низкоуровневых утилит, и все они представлены здесь в порядке уменьшения уровня сложности.
Важно понимать, что высокоуровневые инструменты управления пакетами, такие как aptitude или synaptic , для управления пакетами используют apt , который, в свою очередь, использует dpkg для управления пакетами системы.
See Chapter 2. Debian package management of the Debian reference for more information about the Debian package management utilities. This document is available in various languages and formats, see the Debian Reference entry in the DDP Users’ Manuals overview.
8.1.1. dpkg
Это основная программа управления пакетами. dpkg может вызываться с многими параметрами. Наиболее часто используемые из них:
- Показать список всех параметров: dpkg —help
- Показать управляющий файл (и другую информацию) для указанного пакета: dpkg —info foo_VVV-RRR.deb
- Установить пакет на жёсткий диск (т. е. распаковать и настроить): dpkg —install foo_VVV-RRR.deb
- Распаковать архив Debian на жёсткий диск (но не настраивать): dpkg —unpack foo_VVV-RRR.deb . Учтите, что в результате данной операции пакет не обязан быть в рабочем состоянии; для правильной работы может потребоваться внесение изменений в некоторые файлы. Данная команда удаляет любую ранее установленную версию программы и запускает сценарий preinst указанного пакета (см. Раздел 7.6, «Зачем нужны сценарии preinst, postinst, prerm и postrm?»).
- Настроить пакет, который был распакован ранее: dpkg —configure foo . Кроме всего прочего, эта команда запускает сценарий postinst указанного пакета (см. Раздел 7.6, «Зачем нужны сценарии preinst, postinst, prerm и postrm?»). Она также обновляет файлы, перечисленные в conffiles . Обратите внимание, что в качестве аргумента для параметра configure указывается имя пакета (т. е. foo), а не имя файла-архива Debian (т. е. foo_VVV-RRR.deb).
- Распаковать файл с именем «blurf» (или группу файлов с именем «blurf*») из архива Debian: dpkg —fsys-tarfile foo_VVV-RRR.deb | tar -xf — ‘blurf*’
- Удалить пакет (но не его файлы настроек): dpkg —remove foo
- Удалить пакет (вместе с файлами настроек): dpkg —purge foo
- Вывести состояние установки пакетов, содержащих в имени строку (или регулярное выражение) «foo*»: dpkg —list ‘foo*’
8.1.2. APT
APT is the Advanced Package Tool , an advanced interface to the Debian packaging system which provides the apt-get program. It provides commandline tools for searching and managing packages, and for querying information about them, as well as low-level access to all features of the libapt-pkg library. For more information, see the User’s Guide in /usr/share/doc/apt-doc/guide.html/index.html (you will have to install the apt-doc package).
Starting with Debian Jessie, some frequently used apt-get and apt-cache commands have an equivalent via the new apt binary. This means some popular commands like apt-get update , apt-get install , apt-get remove , apt-cache search , or apt-cache show now can also be called simply via apt , say apt update , apt install , apt remove , apt search , or apt show . The following is an overview of the old and new commands:
apt-get update -> apt update apt-get upgrade -> apt upgrade apt-get dist-upgrade -> apt full-upgrade apt-get install package -> apt install package apt-get remove package -> apt remove package apt-get autoremove -> apt autoremove apt-cache search string -> apt search string apt-cache policy package -> apt list -a package apt-cache show package -> apt show package apt-cache showpkg package -> apt show -a package
Инструмент apt совмещает функциональность apt-get и apt-cache, а также по умолчанию использует красивый цветной формат вывода, что очень удобно. Для использования в сценариях или для продвинутого использования предпочтительнее использовать apt-get (а иногда он просто необходим).
apt-get provides a simple way to retrieve and install packages from multiple sources using the command line. Unlike dpkg , apt-get does not understand .deb files, it works with the packages proper name and can only install .deb archives from a source specified in /etc/apt/sources.list . apt-get will call dpkg directly after downloading the .deb archives [5] from the configured sources.
Часто используемые команды apt-get :
How to Update Debian from Terminal
Debian is a Linux distro composed of free and open-source software (FOSS). It’s developed by the Debian Project, a community-driven project. It’s one of the oldest operating systems based on the Linux kernel. Debian is at the core of many popular operating systems like Ubuntu, Linux Mint, MX Linux, Deepin, and much more.
This guide will demonstrate how to keep Debian’s packages up-to-date from the terminal.
Keeping Debian up-to-date
A Linux operating system is a combination of numerous packages connected with each other in a very complex network. All these packages deliver all the necessary files and binaries that make the operating system.
These packages are generally updated regularly. It may be bug fixes, security patches, or feature improvements. It’s important to keep all the packages up-to-date.
Debian uses APT to manage packages. The package updates are directly available from the official Debian package repos. APT can also work with third-party repos. However, it’s up to you to determine whether the third-party repo is trustworthy and updating their packages.
Updating Debian
We can use APT to perform a check whether any package update is available. If available, we can update the target packages.
It’s also possible to configure automatic updates on Debian using unattended upgrades.
Updating packages require root permission. To perform the actions demonstrated, you need to have access to the root user. Alternatively, you need a non-root user who can execute the sudo command. Learn more on managing sudo permission for users on Debian.
Checking for updates
Open up the terminal and run the following command.
As the output suggests, APT will check for updates on each of the repos configured and update its package catalog. If any update is available, APT will notify you that updates are available.
To check the list of available package updates, run the following APT command.
Upgrading packages
The APT cache is updated with the latest available package catalog. We now also know what package updates are available. Time to install them.
To upgrade a target package, run the following command. Here, APT will only upgrade the target package. If the package weren’t installed already, it wouldn’t be installed.
To upgrade all the packages at once, run the following command instead. Here, APT will download and upgrade all the available package updates.
Before downloading and upgrading packages, APT will ask for confirmation to perform the action. If you don’t want APT to ask for confirmation, add the flag “-y”.
Updating APT cache and upgrading packages simultaneously
Instead of performing these steps simultaneously, we can combine them both in a single command. If you’re running the bash shell, then the following command will check for package updates and upgrade packages simultaneously.
Here, the symbol “&&” ties both the update and upgrade commands together. It’s basically a logical AND operator. There are numerous bash operators and symbols that carry special functions and meanings. Check out this big list of bash operators and their implementations.
Automating Debian update
So far, we’ve updated Debian packages manually. However, manual updating is inconvenient in the long run, not to mention enterprise/professional environment where you may need to manage multiple remote servers at the same time. Updating all of them manually is a tedious process. It’s possible to use Ansible to manually update remote Debian/Ubuntu systems at once but running it manually regularly is not practical.
This is where we can use unattended upgrades. It’s a tool that will automatically check and download package updates whenever available. It requires a little bit of configuration.
First, we need to install the package. Open a terminal, update the APT cache, and install the package.
Next, we need to tweak the APT configuration file for unattended-upgrades. Open it in a text editor.
Uncomment the following lines from the configuration file. It will tell the tool to automate the update process.
The configuration file is updated. Run the following dpkg configuration command to put it into action.
After successful execution, a dialog box will appear on the terminal. Select “Yes”.
The tool will now automatically download and install updates on Debian. However, we need to make sure that it’s working as intended. Check the service status.
It’s showing that the service status is Active (In Progress), meaning it’s working perfectly. Check out this guide on unattended upgrades for full in-depth info and demonstrations.
Final thoughts
Updating Debian is a very simple task. Debian is a well-maintained project with up-to-date packages directly available from its package servers. All you need is to tell APT to do the job.
Debian follows a long-term release cycle. So, you don’t have to upgrade your distro often. If you’re using an older Debian, then instead of updating the packages, it’s recommended to upgrade the distro. At the time of writing this guide, Debian 10 is the latest stable release. Check out this guide on how to upgrade from Debian 9 to Debian 10.
About the author
Sidratul Muntaha
Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.