Ubuntu 软件包管理

文件下载 && 解压缩

  • 下载 wget 链接 -O 保存文件名 -O, --output-document=FILE write documents to FILE,默认输出到当前路径下。
  • 解压zip unzip xxx.zip -d 目标目录 -d extract files into exdir
  • 解压tar.gz tar -zxvf xxx.tar.gz -C 目标目录 -C, --directory=DIR change to directory DIR
    .tgz.tar.gz解压方式相同。
  • 解压tar.xz xz -d -k xxx.tar.xz -d表示解压decompress,-k表示保留原文件(keep)。
  • 其他解压缩
*.tar 用 tar –xvf 解压
*.gz 用 gzip -d或者gunzip 解压
*.tar.gz和*.tgz 用 tar –xzf 解压
*.bz2 用 bzip2 -d或者用bunzip2 解压
*.tar.bz2用tar –xjf 解压
*.Z 用 uncompress 解压
*.tar.Z 用tar –xZf 解压
*.rar 用 unrar e解压
*.zip 用 unzip 解压

软件管理常用命令

  • 安装软件 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 search mysql-serverapt-cache 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.

源管理

  • 配置文件路径 /etc/apt/sources.list
  • 添加仓库 add-apt-repository xxxadd-apt-repository ppa:fcitx-team/nightly
  • 更新源 apt-get update
  • 升级 apt-get upgrade
  • 智能升级 apt-get dist-upgrade

包管理工具

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

  • apt

    扫描二维码关注公众号,回复: 9197035 查看本文章
    • 列出已安装的软件 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

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.

apt的三种参数update upgrade dist-upgrade的区别

  • update 更新源
update is used to resynchronize the packageindex files from their sources. 
The indexes of available packages are fetchedfrom the location(s) specified in /etc/apt/sources.list. 
  • upgrade 升级软件包(有冲突则优先保留当前版本,不做升级)
upgrade is used to install the newestversions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list.
  • dist-upgrade 智能升级
dist-upgrade in addition to performing the function of upgrade, 
also intelligently handles changing dependencies with new versions of packages; 
apt-get has a"smart" conflict resolution system, 
and it will attempt to upgrade the most important packages at the expense of lessimportant ones if necessary. 
发布了270 篇原创文章 · 获赞 156 · 访问量 29万+

猜你喜欢

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