Lenh dpkg trong linux

dpkg is the base command for handling Debian packages on the system. If you have .deb packages, it is dpkg that allows installation or analysis of their contents. But this program only has a partial view of the Debian universe: it knows what is installed on the system, and whatever it is given on the command line, but knows nothing of the other available packages. As such, it will fail if a dependency is not met. Tools such as apt and aptitude, on the contrary, will create a list of dependencies to install everything as automatically as possible.

5.4.1. Cài đặt Gói

dpkg là công cụ cài đặt gói Debian đã có sẵn [vì nó không tải bất cứ thứ gì]. Để thực hiện việc này, chúng ta sử dụng tùy chọn -i hoặc --install.

Ví dụ 5.2. Cài đặt một gói với dpkg

# dpkg -i man-db_2.9.4-2_amd64.deb
[Reading database ... 227466 files and directories currently installed.]
Preparing to unpack man-db_2.9.4-2_amd64.deb ...
Unpacking man-db [2.9.4-2] over [2.8.5-2] ...
Setting up man-db [2.9.4-2] ...
Updating database of manual pages ...
man-db.service is a disabled or a static unit not running, not starting it.
Processing triggers for mailcap [3.69] ...

We can see the different steps performed by dpkg; we know, thus, at what point any error may have occurred. The installation can also be effected in two stages: first unpacking, then configuration. apt takes advantage of this, limiting the number of calls to dpkg [since each call is costly, due to loading of the database in memory, especially the list of already installed files].

Ví dụ 5.3. Giải nén và cấu hình riêng rẽ

# dpkg --unpack man-db_2.9.4-2_amd64.deb
[Reading database ... 227466 files and directories currently installed.]
Preparing to unpack man-db_2.9.4-2_amd64.deb ...
Unpacking man-db [2.9.4-2] over [2.9.4-2] ...
Processing triggers for mailcap [3.69] ...
# dpkg --configure man-db
Setting up man-db [2.9.4-2] ...
Updating database of manual pages ...
man-db.service is a disabled or a static unit not running, not starting it.

Đôi khi dpkg sẽ không cài đặt gói và trả về lỗi; Nếu người dùng cho nó để bỏ qua điều này, nó sẽ chỉ phát hành một cảnh báo; Vì lý do này mà chúng ta có các tùy chọn --force-* khác nhau. Lệnh dpkg --force-help là tài liệu đầy đủ các tùy chọn này. Lỗi thường gặp nhất, mà bạn sẽ gặp phải sớm hay muộn, là một va chạm tập tin. Khi một gói chứa một tập tin đã được cài đặt bởi một gói khác, dpkg sẽ từ chối cài đặt nó. Sau đó các thông báo sau sẽ xuất hiện:

Unpacking libgdm [from .../libgdm_3.8.3-2_amd64.deb] ...
dpkg: error processing /var/cache/apt/archives/libgdm_3.8.3-2_amd64.deb [--unpack]:
 trying to overwrite '/usr/bin/gdmflexiserver', which is also in package gdm3 3.4.1-9

Trong trường hợp này, nếu bạn nghĩ rằng thay thế tệp này không phải ảnh hướng tới tính ổn định của hệ thống [thường là trường hợp này], bạn có thể sử dụng tùy chọn --force-overwrite, để cho dpkg biết để bỏ qua lỗi này và ghi đè lên tệp.

While there are many available --force-* options, only --force-overwrite is likely to be used regularly. These options only exist for exceptional situations, rarely encountered in Debian Stable. It is better to leave them alone as much as possible in order to respect the rules imposed by the packaging mechanism. Do not forget, these rules ensure the consistency and stability of your system.

5.4.2. Xóa Gói

Invoking dpkg with the -r or --remove option, followed by the name of a package, removes that package. This removal is, however, not complete: all of the configuration files, maintainer scripts, log files [system logs] and other user data handled by the package remain. That way disabling the program is easily done by uninstalling it, and it is still possible to quickly reinstall it with the same configuration. To completely remove everything associated with a package, use the -P or --purge option, followed by the package name.

Ví dụ 5.4. Xoá và tẩy gói debian-cd

# dpkg -r debian-cd
[Reading database ... 228705 files and directories currently installed.]
Removing debian-cd [3.1.35] ...
# dpkg -P debian-cd
[Reading database ... 228049 files and directories currently installed.]
Purging configuration files for debian-cd [3.1.35] ...

5.4.3. Truy vấn cơ sở dữ liệu của dpkg và kiểm tra các tệp .deb

Before concluding this section, we will study dpkg options that query the internal database in order to obtain information. Giving first the long options and then corresponding short options [that will evidently take the same possible arguments] we cite

  • --listfiles package [or -L], which lists the files installed by this package;

  • --search file [or -S], which finds the package[s] containing the file;

  • --status package [or -s], which displays the headers of an installed package;

  • --list [or -l], which displays the list of packages known to the system and their installation status;

  • --contents file.deb [or -c], which lists the files in the Debian package specified;

  • --info file.deb [or -I], which displays the headers of this Debian package.

Ví dụ 5.5. Các truy vấn khác nhau với dpkg

$ dpkg -L base-passwd
/.
/usr
/usr/sbin
/usr/sbin/update-passwd
/usr/share
/usr/share/base-passwd
/usr/share/base-passwd/group.master
/usr/share/base-passwd/passwd.master
/usr/share/doc
/usr/share/doc/base-passwd
/usr/share/doc/base-passwd/README
/usr/share/doc/base-passwd/changelog.gz
/usr/share/doc/base-passwd/copyright
/usr/share/doc/base-passwd/users-and-groups.html
/usr/share/doc/base-passwd/users-and-groups.txt.gz
/usr/share/doc-base
/usr/share/doc-base/users-and-groups
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/base-passwd
/usr/share/man
/usr/share/man/de
/usr/share/man/de/man8
/usr/share/man/de/man8/update-passwd.8.gz
/usr/share/man/es
/usr/share/man/es/man8
/usr/share/man/es/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/man/ja
/usr/share/man/ja/man8
/usr/share/man/ja/man8/update-passwd.8.gz
/usr/share/man/man8
/usr/share/man/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/ru
/usr/share/man/ru/man8
/usr/share/man/ru/man8/update-passwd.8.gz
$ dpkg -S /bin/date
coreutils: /bin/date
$ dpkg -s coreutils
Package: coreutils
Essential: yes
Status: install ok installed
Priority: required
Section: utils
Installed-Size: 17478
Maintainer: Michael Stone 
Architecture: amd64
Multi-Arch: foreign
Source: coreutils [8.32-4]
Version: 8.32-4+b1
Pre-Depends: libacl1 [>= 2.2.23], libattr1 [>= 1:2.4.44], libc6 [>= 2.28], libgmp10, libselinux1 [>= 3.1~]
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 numfmt
 od paste pathchk pinky pr printenv printf ptx pwd readlink realpath 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: //gnu.org/software/coreutils
$ dpkg -l 'b*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=[none]/Reinst-required [Status,Err: uppercase=bad]
||/ Name                       Version       Architecture Description
+++-==========================-==============-============-==================================
un  backupninja                                [no description available]
un  backuppc                                   [no description available]
ii  baloo-kf5                  5.78.0-3       amd64        framework for searching and manag>
un  balsa                                      [no description available]
ii  baobab                     3.38.0-1       amd64        GNOME disk usage analyzer
un  base                                       [no description available]
un  base-config                                [no description available]
ii  base-files                 11.1           amd64        Debian base system miscellaneous >
ii  base-passwd                3.5.51         amd64        Debian base system master passwor>
ii  bash                       5.1-2+b1       amd64        GNU Bourne Again SHell
[..]
$ dpkg -c /var/cache/apt/archives/bash_5.1-3+b1_amd64.deb
drwxr-xr-x root/root         0 2021-07-25 20:43 ./
drwxr-xr-x root/root         0 2021-07-25 20:43 ./bin/
-rwxr-xr-x root/root   1234376 2021-07-25 20:43 ./bin/bash
drwxr-xr-x root/root         0 2021-07-25 20:43 ./etc/
-rw-r--r-- root/root      1994 2021-07-25 20:43 ./etc/bash.bashrc
drwxr-xr-x root/root         0 2021-07-25 20:43 ./etc/skel/
-rw-r--r-- root/root       220 2021-07-25 20:43 ./etc/skel/.bash_logout
-rw-r--r-- root/root      3526 2021-07-25 20:43 ./etc/skel/.bashrc
-rw-r--r-- root/root       807 2021-07-25 20:43 ./etc/skel/.profile
drwxr-xr-x root/root         0 2021-07-25 20:43 ./usr/
drwxr-xr-x root/root         0 2021-07-25 20:43 ./usr/bin/
-rwxr-xr-x root/root      6759 2021-07-25 20:43 ./usr/bin/bashbug
-rwxr-xr-x root/root     14648 2021-07-25 20:43 ./usr/bin/clear_console
drwxr-xr-x root/root         0 2021-07-25 20:43 ./usr/share/
drwxr-xr-x root/root         0 2021-07-25 20:43 ./usr/share/doc/
[..]
$ dpkg -I /var/cache/apt/archives/bash_5.1-3+b1_amd64.deb
 new Debian package, version 2.0.
 size 1416600 bytes: control archive=7256 bytes.
      77 bytes,     4 lines      conffiles
    1030 bytes,    27 lines      control
    4511 bytes,    64 lines      md5sums
     603 bytes,    31 lines   *  postinst             #!/bin/bash
     500 bytes,    25 lines   *  postrm               #!/bin/sh
   14536 bytes,    33 lines   *  preinst              
     289 bytes,    22 lines   *  prerm                #!/bin/bash
 Package: bash
 Source: bash [5.1-3]
 Version: 5.1-3+b1
 Architecture: amd64
 Essential: yes
 Maintainer: Matthias Klose 
 Installed-Size: 6470
 Pre-Depends: libc6 [>= 2.25], libtinfo6 [>= 6]
 Depends: base-files [>= 2.1.12], debianutils [>= 2.15]
 Recommends: bash-completion [>= 20060301-0]
 Suggests: bash-doc
 Conflicts: bash-completion [

Bài Viết Liên Quan

Chủ Đề