dpkg 命令介绍

发布时间: 更新时间: 总字数:900 阅读时间:2m 作者: IP上海 分享 网址

本文介绍dpkg的安装和使用。dpkg命令是Debian Linux系统用来安装、创建和管理软件包的实用工具。


apt install dpkg-dev debhelper


$ dpkg --help
Usage: dpkg [<option> ...] <command>

  -i|--install       <.deb file name>... | -R|--recursive <directory>...
  --unpack           <.deb file name>... | -R|--recursive <directory>...
  -A|--record-avail  <.deb file name>... | -R|--recursive <directory>...
  --configure        <package>... | -a|--pending
  --triggers-only    <package>... | -a|--pending
  -r|--remove        <package>... | -a|--pending
  -P|--purge         <package>... | -a|--pending
  -V|--verify [<package>...]       Verify the integrity of package(s).
  --get-selections [<pattern>...]  Get list of selections to stdout.
  --set-selections                 Set package selections from stdin.
  --clear-selections               Deselect every non-essential package.
  --update-avail [<Packages-file>] Replace available packages info.
  --merge-avail [<Packages-file>]  Merge with info from file.
  --clear-avail                    Erase existing available info.
  --forget-old-unavail             Forget uninstalled unavailable pkgs.
  -s|--status [<package>...]       Display package status details.
  -p|--print-avail [<package>...]  Display available version details.
  -L|--listfiles <package>...      List files 'owned' by package(s).
  -l|--list [<pattern>...]         List packages concisely.
  -S|--search <pattern>...         Find package(s) owning file(s).
  -C|--audit [<package>...]        Check for broken package(s).
  --yet-to-unpack                  Print packages selected for installation.
  --predep-package                 Print pre-dependencies to unpack.
  --add-architecture <arch>        Add <arch> to the list of architectures.
  --remove-architecture <arch>     Remove <arch> from the list of architectures.
  --print-architecture             Print dpkg architecture.
  --print-foreign-architectures    Print allowed foreign architectures.
  --assert-<feature>               Assert support for the specified feature.
  --validate-<thing> <string>      Validate a <thing>'s <string>.
  --compare-versions <a> <op> <b>  Compare version numbers - see below.
  --force-help                     Show help on forcing.
  -Dh|--debug=help                 Show help on debugging.

  -?, --help                       Show this help message.
      --version                    Show the version.

Assertable features: support-predepends, working-epoch, long-filenames,
  multi-conrep, multi-arch, versioned-provides.

Validatable things: pkgname, archname, trigname, version.

Use dpkg with -b, --build, -c, --contents, -e, --control, -I, --info,
  -f, --field, -x, --extract, -X, --vextract, --ctrl-tarfile, --fsys-tarfile
on archives (type dpkg-deb --help).

  --admindir=<directory>     Use <directory> instead of /var/lib/dpkg.
  --root=<directory>         Install on a different root directory.
  --instdir=<directory>      Change installation dir without changing admin dir.
  --path-exclude=<pattern>   Do not install paths which match a shell pattern.
  --path-include=<pattern>   Re-include a pattern after a previous exclusion.
  -O|--selected-only         Skip packages not selected for install/upgrade.
  -E|--skip-same-version     Skip packages whose same version is installed.
  -G|--refuse-downgrade      Skip packages with earlier version than installed.
  -B|--auto-deconfigure      Install even if it would break some other package.
  --[no-]triggers            Skip or force consequential trigger processing.
  --verify-format=<format>   Verify output format (supported: 'rpm').
  --no-debsig                Do not try to verify package signatures.
                             Just say what we would do - don't do it.
  -D|--debug=<octal>         Enable debugging (see -Dhelp or --debug=help).
  --status-fd <n>            Send status change updates to file descriptor <n>.
  --status-logger=<command>  Send status change updates to <command>'s stdin.
  --log=<filename>           Log status changes and actions to <filename>.
                             Ignore dependencies involving <package>.
  --force-...                Override problems (see --force-help).
                             Stop when problems encountered.
  --abort-after <n>          Abort after encountering <n> errors.

Comparison operators for --compare-versions are:
  lt le eq ne ge gt       (treat empty version as earlier than any version);
  lt-nl le-nl ge-nl gt-nl (treat empty version as later than any version);
  < << <= = >= >> >       (only for compatibility with control file syntax).

Use 'apt' or 'aptitude' for user-friendly package management.


  • 安装 dpkg -i|--install <.deb file name>
  • 解包 dpkg --unpack <.deb file name>
  • 解压安装包 dpkg -x <.deb file name> <dir>
  • 卸载 dpkg -r|--remove <package>
  • 查询安装包状态 dpkg -s|--status [<package>...]
  • 查询安装包信息 dpkg --info [<package>...]
  • 查看软件包配置 dpkg --configure <package>...
  • 列举文件 dpkg -L|--listfiles <package>
  • 打包 dpkg -b, --build


# 1. init dir
mkdir pkg
cd pkg
mkdir -p usr/src
mkdir -p usr/lib
mkdir -p usr/bin
mkdir DEBIAN

# 2. touch file
cp <sour..> usr/bin

# 3. init control
$ vim DEBIAN/control
Package: test-pkg
Version: 1.0.0
Section: utils
Priority: optional
Architecture: [x86-64|amd64]
Installed-Size: 512
Maintainer: me@xiexianbin.cn
Description: test package

# 4. build deb package
$ sudo chmod 755 * -R
$ dpkg -b . /root/test-pkg_1.0.0_amd64.deb
dpkg-deb: building package 'test-pkg' in '/root/test-pkg_1.0.0_amd64.deb'.
$ dpkg -i /root/test-pkg_1.0.0_amd64.deb
Selecting previously unselected package test-pkg.
(Reading database ... 204008 files and directories currently installed.)
Preparing to unpack /root/test-pkg_1.0.0_amd64.deb ...
Unpacking test-pkg (1.0.0) ...
Setting up test-pkg (1.0.0) ...
$ dpkg -l test-pkg
| 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
ii  test-pkg       1.0.0        amd64        test package


  • /etc/apt/sources.list 中配置 deb-src
  • 编译环境初始化
apt update
apt-get install dpkg-dev debhelper
  • 获取已有源码包
mkdir build-redis && cd build-redis
apt-get source redis
  • 编译
cd redis.x.x
find ../*.deb

编译 curl

# 安装 gcc、make 等编译链工具
apt-get update
apt-get install -y build-essential

# 创建编译目录
mkdir -p ~/build && cd ~/build

# 安装编译 curl 依赖的那些软件包
apt-get build-dep curl

# 下载构建curl deb包的源码
apt source curl

# 切换到构建目录
cd curl-x.x.x/

# 构建deb包,该条命令执行后,在上一层目录下就会生成 deb 包
dpkg-buildpackage -us -uc -b


  1. https://www.debian.org/distrib/packages
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数