Ubuntu包管理器APT命令

各个版本的Ubuntu更新源参考:
Ubuntu 23.04、22.04、20.04、18.04国内源–阿里云、中科大、163、清华更新源

apt update
更新本地的软件信息数据库,不会安装或者更新任何本地软件包。

apt update
[sudo] password for dev: 
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.163.com/ubuntu bionic InRelease                                          
Get:3 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]                    
Hit:4 http://mirrors.163.com/ubuntu bionic-security InRelease                                 
Hit:5 http://packages.microsoft.com/repos/code stable InRelease                               
Hit:6 https://download.docker.com/linux/ubuntu bionic InRelease                               
Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease                                 
Hit:8 http://mirrors.163.com/ubuntu bionic-updates InRelease                                  
Hit:9 https://packages.microsoft.com/repos/edge stable InRelease                              
Get:10 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB]                    
Hit:11 http://mirrors.163.com/ubuntu bionic-proposed InRelease                                
Hit:12 http://mirrors.163.com/ubuntu bionic-backports InRelease                               
Hit:13 https://packages.microsoft.com/ubuntu/18.04/prod bionic InRelease                      
Get:14 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease [83.3 kB]                  
Get:15 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease [242 kB]                    
Ign:16 https://www.scootersoftware.com bcompare4 InRelease                     
Hit:17 https://www.scootersoftware.com bcompare4 Release                       
Get:19 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [76.8 kB]

apt upgrade [-y]
apt-get dist-upgrade 升级时自动处理依赖包,会自动安装或者升级

apt full-upgrade 会根据需要删除已经安装的软件,upgrade不会

apt install pkg1 pkg2 pkg3

apt install chromi (2次tab显示候选项或者补全,类似shell中命令自动补齐)

apt install pkg1 --no-upgrade
apt install pkg1 --only-upgrade
apt install pkg1=version

apt remove pkg1 卸载软件,保留配置文件,方便重装时恢复软件设置。大部分情况够用。
apt purge pkg1 删除软件所有数据,包括配置文件,不会修改home目录下的数据或配置
apt autoremove 自动删除已卸载软件的依赖库
apt --purge autoremove

apt search key-word
支持正则表达式

apt show pkg_name

apt depends chromium-browser
apt rdepends chromium-browser

扫描二维码关注公众号,回复: 15347744 查看本文章

apt download pkgname

apt list --upgradable / --installed / --all-versions

apt-cache policy chromium-browser
apt policy

$ apt policy chromium-browser
policy chromium-browser
chromium-browser:
  Installed: 111.0.5563.64-0ubuntu0.18.04.5
  Candidate: 111.0.5563.64-0ubuntu0.18.04.5
  Version table:
 *** 111.0.5563.64-0ubuntu0.18.04.5 500
        500 http://mirrors.aliyun.com/ubuntu bionic-security/universe amd64 Packages
        500 http://mirrors.aliyun.com/ubuntu bionic-updates/universe amd64 Packages
        500 http://mirrors.163.com/ubuntu bionic-security/universe amd64 Packages
        500 http://mirrors.163.com/ubuntu bionic-updates/universe amd64 Packages
        100 /var/lib/dpkg/status
     65.0.3325.181-0ubuntu1 500
        500 http://mirrors.aliyun.com/ubuntu bionic/universe amd64 Packages
        500 http://mirrors.163.com/ubuntu bionic/universe amd64 Packages

apt-mark hold pkgname 标记不自动升级
apt-mark unhold pkgname

缓存目录
/var/cache/apt/archives/

apt autoclean 清除过时软件包
apt clean 清除所有缓存

历史记录文件:
/var/log/apt/history.log

引入apt命令集就是为了解决这个问题。apt由一些来自apt-get和apt-cache且广泛使用的特性组成,同时搁置了那些令人费解且少用的特性。它也能管理apt.conf文件。

使用apt,你不必在apt-get和apt-cache命令间来回切换。apt更加的结构化,给你提供必要选项,来管理软件包。

猜你喜欢

转载自blog.csdn.net/yinminsumeng/article/details/129706416