Ubuntu 包管理工具 apt-get dpkg 常用操作

总目录 - Ubuntu 应用软件安装 && 开发环境搭建测试 目录

安装卸载等高频命令

  • 安装软件 apt-get install xxxdpkg -i xxx.deb

  • 查看软件安装位置 dpkg -L xxxdpkg-query -L xxx

  • 卸载软件 apt-get remove xxx --purgedpkg -r xxx.deb
    一般使用前三个足够。Demo: sqlite3的命令行安装、卸载及安装位置查询

  • 版本相关

    • 查询软件有什么版本 apt-cache madison 包名apt-cache policy 包名
    • 安装指定版本的软件包 apt-get install 包名=版本信息
    • 查询已安装软件的版本 dpkg -l 包名
  • 查询可以安装的软件(如mysql-server)名称 apt-cache search mysql-serverapt search mysql-server

  • 查看已安装软件包列表 apt list --installeddpkg -l

  • dpkg的-l-L区别

  -L|--listfiles <package> ...     List files 'owned' by package(s).
  -l|--list [<pattern> ...]        List packages concisely.

包管理工具 Intro

Debian系的Linux发行版的两种包管理工具:
apt (Advanced Packaging Tools) 高级包管理工具(install安装,remove移除)
dpkg Debian package,直接操作下载好的软件包文件(-i安装,-r移除)。
关系:apt是基于dpkg的。

  • apt

    • 列出已安装的软件 apt list --installed
    • 安装 apt-get install xxx
    • 卸载 apt-get remove xxx Remove packages
      自动卸载 apt-get autoremove Remove automatically all unused packages
      卸载并清除配置 apt-get remove --purge xxx
    • 清理系统/删除下载好的软件包
      apt-get clean Erase downloaded archive files
      apt-get autoclean Erase old downloaded archive files
    • 根据正则表达式搜索软件包列表 apt-cache search xxx
    • 显示该软件包的依赖关系信息 apt-cache depends xxx
  • dpkg (Package manager for Debian) Debian系的包管理工具

    • 安装 dpkg -i xxx.deb -i--install
    • 卸载 dpkg -r xxx.deb -r--remove
      -p--purge选项表示卸载的同时清除配置文件。
    • 搜索含有指定文件的软件包 dpkg -s xxx--search
    • 列出属于指定软件包的文件 dpkg -L xxx.deb--listfiles
    • 列出软件包的状态 dpkg -l xxx--list
    • 查看软件包信息 dpkg -info xxx.deb
    • 重新配置软件包 dpkg-reconfigure xxx

apt相关工具

wuyujin@ubuntu18:~$ apt-
apt-add-repository    apt-cdrom             apt-extracttemplates  apt-get               apt-mark              
apt-cache             apt-config            apt-ftparchive        apt-key               apt-sortpkgs          

wuyujin@ubuntu18:~$ whatis apt
apt (8)              - command-line interface

wuyujin@ubuntu18:~$ whatis apt-add-repository
apt-add-repository (1) - Adds a repository into the /etc/apt/sources.list or /etc/apt/sources.list.d or removes an existing one

wuyujin@ubuntu18:~$ whatis apt-cdrom
apt-cdrom (8)        - APT CD-ROM management utility

wuyujin@ubuntu18:~$ whatis apt-extracttemplates 
apt-extracttemplates (1) - Utility to extract debconf config and templates from Debian packages

wuyujin@ubuntu18:~$ whatis apt-get
apt-get (8)          - APT package handling utility - - command-line interface

wuyujin@ubuntu18:~$ whatis apt-mark
apt-mark (8)         - show, set and unset various settings for a package

wuyujin@ubuntu18:~$ whatis apt-cache
apt-cache (8)        - query the APT cache

wuyujin@ubuntu18:~$ whatis apt-config
apt-config (8)       - APT Configuration Query program

wuyujin@ubuntu18:~$ whatis apt-ftparchive
apt-ftparchive (1)   - Utility to generate index files

wuyujin@ubuntu18:~$ whatis apt-key
apt-key (8)          - APT key management utility

wuyujin@ubuntu18:~$ whatis apt-sortpkgs
apt-sortpkgs (1)     - Utility to sort package index files
wuyujin@ubuntu18:~$ 

More Options

  • apt --help
    install 安装软件包
    remove 移除软件包
    search 搜索软件包描述
    list 根据名称列出软件包
    show 显示软件包细节
    autoremove 自动移除不再使用的软件包
    update 更新可用软件包列表
    upgrade 通过 安装/升级 软件来更新系统
    full-upgrade 通过 卸载/安装/升级 来更新系统
    edit-sources 编辑软件源信息文件

  • apt-get --help
    update 取回更新的软件包列表信息
    upgrade 进行一次升级
    install 安装新的软件包(注:软件包名称是 libc6 而非 libc6.deb)
    remove 卸载软件包
    purge 卸载并清除软件包的配置
    autoremove 自动移除不再使用的软件包
    dist-upgrade 发行版升级,见 apt-get(8)
    dselect-upgrade 根据 dselect 的选择来进行升级
    build-dep 为源码包配置所需的编译依赖关系
    clean 删除所有已下载的包文件
    autoclean 删除已下载的旧包文件
    check 核对以确认系统的依赖关系的完整性
    source 下载源码包文件
    download 下载指定的二进制包到当前目录
    changelog 下载指定软件包,并显示其变更日志(changelog)

  • apt-cache --help
    showsrc Show source records
    search Search the package list for a regex pattern
    depends Show raw dependency information for a package
    rdepends Show reverse dependency information for a package
    show Show a readable record for the package
    pkgnames List the names of all packages in the system
    policy Show policy settings

  • dpkg --help

Usage: dpkg [<option> ...] <command>

Commands:
  -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.
发布了283 篇原创文章 · 获赞 156 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/wuyujin1997/article/details/104347219