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 · 訪問量 30萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章