• apt、apt-get、apt-cache使用详解


    1. 概述

    aptapt-getapt-cache是三个软件,但可以将apt理解为apt-get、apt-cache的超集,因为apt包含了apt-getapt-cache

    2. 搜索软件、查看软件信息、依赖关系

    # 搜索指定的包
    apt search packagename
    或
    apt-cache search packagename  
    
    #显示包的相关信息,如说明、大小、版本等
    apt show packagename
    或
    apt-cache show packagename 
    	 
    #了解使用该包依赖哪些包
    apt-cache depends packagename  
    
    #查看该包被哪些包依赖
    apt-cache rdepends packagename 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    3. 查看已安装软件

    apt list
    或
    apt-cache pkgnames
    
    • 1
    • 2
    • 3

    4. 安装、升级软件

    # 更新软件库 建议安装之前先执行该操作
    apt update
    或
    apt-get update
    
    # 安装软件
    apt install packagename
    或
    apt-get install packagename
    
    # 升级已安装的软件
    apt upgrade
    或
    apt-get upgrade
    
    # 仅升级指定的包
    apt-get install packagename --only-upgrade
    
    # 重新安装包
    apt-get install packagename --reinstall
    
    # 修复安装
    apt-get -f install
    
    # 安装相关的编译环境
    apt-get build-dep packagename
    
    # 下载该包的源代码
    apt-get source packagename
    
    # 升级系统
    apt-get dist-upgrade
    
    # 使用 dselect 升级
    apt-get dselect-upgrade
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    5. 删除

    # 删除包 保留配置文件
    apt remove packagename
    或
    apt-get remove packagename
    
    # 删除包,包括删除配置文件等
    apt-get remove packagename -- purge
    
    # 删除包及其依赖的软件包+配置文件等
    apt-get autoremove packagename --purge
    
    # 删除所有未使用的包 
    apt autoremove
    或
    apt-get autoremove 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    6. 清理、检查

    # 清理无用的包 删除包缓存中的所有包
    apt-get clean
    
    # 清理无用的包 将已经删除了的软件包的.deb安装文件从硬盘中删除掉
    apt-get autoclean
    
    • 1
    • 2
    • 3
    • 4
    • 5

    7. 忽略更新

    # 使用这个命令可以将指定的包的版本hold住,这样在更新的时候就会忽略掉这个包
    apt-mark hold packagename		
    
    # 解除对包的锁定
    apt-mark unhold packagename
    
    • 1
    • 2
    • 3
    • 4
    • 5

    8. apt-get参数

     -h 		帮助文件。  
     -q 		输出到日志 - 无进展指示  
     -qq 		不输出信息,错误除外  
     -d 		仅下载 - 不安装或解压归档文件  
     -s 		不实际安装。模拟执行命令  
     -y 		在需要确认的场景中回应 yes
     -f 		尝试修正系统依赖损坏处  
     -m 		如果归档无法定位,尝试继续  
     -u 		同时显示更新软件包的列表  
     -b 		获取源码包后编译  
     -V 		显示详细的版本号  
     -c=? 		阅读此配置文件  
     -o=? 		设置自定的配置选项,如 -o dir::cache=/tmp  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    9. 参考文档

    apt --help
    
    apt 2.0.2ubuntu0.1 (amd64)
    Usage: apt [options] command
    
    apt is a commandline package manager and provides commands for
    searching and managing as well as querying information about packages.
    It provides the same functionality as the specialized APT tools,
    like apt-get and apt-cache, but enables options more suitable for
    interactive use by default.
    
    Most used commands:
      list - list packages based on package names
      search - search in package descriptions
      show - show package details
      install - install packages
      reinstall - reinstall packages
      remove - remove packages
      autoremove - Remove automatically all unused packages
      update - update list of available packages
      upgrade - upgrade the system by installing/upgrading packages
      full-upgrade - upgrade the system by removing/installing/upgrading packages
      edit-sources - edit the source information file
      satisfy - satisfy dependency strings
    
    See apt(8) for more information about the available commands.
    Configuration options and syntax is detailed in apt.conf(5).
    Information about how to configure sources can be found in sources.list(5).
    Package and version choices can be expressed via apt_preferences(5).
    Security details are available in apt-secure(8).
    This APT has Super Cow Powers.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    apt-get --help
    
    apt 2.0.2ubuntu0.1 (amd64)
    Usage: apt-get [options] command
           apt-get [options] install|remove pkg1 [pkg2 ...]
           apt-get [options] source pkg1 [pkg2 ...]
    
    apt-get is a command line interface for retrieval of packages
    and information about them from authenticated sources and
    for installation, upgrade and removal of packages together
    with their dependencies.
    
    Most used commands:
      update - Retrieve new lists of packages
      upgrade - Perform an upgrade
      install - Install new packages (pkg is libc6 not libc6.deb)
      reinstall - Reinstall packages (pkg is libc6 not libc6.deb)
      remove - Remove packages
      purge - Remove packages and config files
      autoremove - Remove automatically all unused packages
      dist-upgrade - Distribution upgrade, see apt-get(8)
      dselect-upgrade - Follow dselect selections
      build-dep - Configure build-dependencies for source packages
      satisfy - Satisfy dependency strings
      clean - Erase downloaded archive files
      autoclean - Erase old downloaded archive files
      check - Verify that there are no broken dependencies
      source - Download source archives
      download - Download the binary package into the current directory
      changelog - Download and display the changelog for the given package
    
    See apt(8) for more information about the available commands.
    Configuration options and syntax is detailed in apt.conf(5).
    Information about how to configure sources can be found in sources.list(5).
    Package and version choices can be expressed via apt_preferences(5).
    Security details are available in apt-secure(8).
    This APT has Super Cow Powers.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    apt-cache --help
    
    apt 2.0.2ubuntu0.1 (amd64)
    Usage: apt-cache [options] command
           apt-cache [options] show pkg1 [pkg2 ...]
    
    apt-cache queries and displays available information about installed
    and installable packages. It works exclusively on the data acquired
    into the local cache via the 'update' command of e.g. apt-get. The
    displayed information may therefore be outdated if the last update was
    too long ago, but in exchange apt-cache works independently of the
    availability of the configured sources (e.g. offline).
    
    Most used commands:
      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
    
    See apt(8) for more information about the available commands.
    Configuration options and syntax is detailed in apt.conf(5).
    Information about how to configure sources can be found in sources.list(5).
    Package and version choices can be expressed via apt_preferences(5).
    Security details are available in apt-secure(8).
    This APT has Super Cow Powers.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  • 相关阅读:
    病情预测:指示病情程度、预测病情指标(深度学习和Python)
    有重复元素的快速排序
    如何在Ubuntu 22.04使用wine安装windows版本微信
    Buildroot 添加 Qt 支持
    突然想散步
    企业电子招投标采购系统——功能模块&功能描述+数字化采购管理 采购招投标
    【车牌识别】基于BP神经网络实现车牌识别(带语音播报)含Matlab源码
    IOS – OpenGL ES 图像侵蚀边缘色彩模糊 GPUImageRGBErosionFilter
    『现学现忘』Git基础 — 17、Commit对象
    leetcode刷题:动态规划02(爬楼梯)
  • 原文地址:https://blog.csdn.net/weixin_52341477/article/details/127778082