Kali Linux apt 包管理工具命令详解
详解 Kali Linux Rolling 的 apt/apt-get/dpkg 包管理工具,覆盖软件源配置、search、update、install、remove、purge、autoremove、list、show、clean、history、upgrade、dist-upgrade 及离线 deb 安装,所有回显均为 Kali Rolling 实测结果
Kali Linux apt 包管理工具命令详解
目标:详解 Kali Linux Rolling 的 apt / apt-get / dpkg 包管理工具,覆盖软件源配置、搜索、安装、卸载、查询、缓存、历史与升级全套命令,并演示离线 deb 安装。所有命令与回显均为 Kali Rolling 实测结果。
一、环境信息
- 操作系统:Kali GNU/Linux Rolling(
VERSION_ID=2026.3,VERSION_CODENAME=kali-rolling,Debian 系) - apt:
apt 3.3.3 (amd64)(apt 与 apt-get 同版本) - dpkg:
Debian 'dpkg' package management program version 1.23.7 (amd64)
二、apt 包管理器概览
Kali 的包管理基于 dpkg,apt 在其上提供仓库解析、依赖自动处理等能力:
| 命令 | 定位 |
|---|---|
| dpkg | 底层包管理,直接操作 .deb,不做依赖解析 |
| apt-get | 经典前端,脚本友好,输出稳定 |
| apt | 面向交互的新前端,带进度条与彩色输出 |
仓库位置与配置文件
Kali 使用 deb822 格式源文件,主源在 /etc/apt/sources.list.d/kali.sources:
ls /etc/apt/sources.list.d/
cat /etc/apt/sources.list.d/kali.sources
docker.list
kali.sources
Types: deb
URIs: http://http.kali.org/kali/
Suites: kali-rolling
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/kali-archive-keyring.gpg
💡
http.kali.org是官方轮询域名,实测会自动重定向到国内可用镜像(本机命中了mirror.nju.edu.cn)。第三方仓库 GPG 密钥按惯例放/etc/apt/keyrings/。
三、软件源配置(官方源/国内镜像源)
1. 官方源验证
执行刷新验证 kali-rolling 主源可用:
apt-get update
Hit:1 https://mirrors.aliyun.com/docker-ce/linux/debian trixie InRelease
Get:2 http://mirror.nju.edu.cn/kali kali-rolling InRelease [34.0 kB]
Get:3 http://mirror.nju.edu.cn/kali kali-rolling/main amd64 Packages [21.6 MB]
Fetched 21.6 MB in 3s (8054 kB/s)
Reading package lists...
💡 也可手动把
URIs替换为https://mirrors.aliyun.com/kali/等国内镜像,Suites: kali-rolling保持不变。
2. 第三方仓库示例:阿里云 docker-ce 源
Kali 代号 kali-rolling 无 docker-ce 通道,映射 Debian trixie 稳定通道:
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian trixie stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
cat /etc/apt/sources.list.d/docker.list
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian trixie stable
四、search 搜索
apt search 是全文搜索,按包名与描述匹配:
apt search sl
apt-cache search sl
Sorting...
Full Text Search...
2048/kali-rolling 1.0.3-1 amd64
Slide and add puzzle game for text mode
2048-qt/kali-rolling 0.1.6-2+b4 amd64
mathematics based puzzle game
docker-ce-rootless-extras - Rootless support for Docker.
2048 - Slide and add puzzle game for text mode
2048-qt - mathematics based puzzle game
4g8 - Packet Capture and Interception for Switched Networks
💡 想精确定位可用
apt list -a <包名>。
五、update 刷新仓库
apt-get update
apt update # 两种写法等价
Hit:1 https://mirrors.aliyun.com/docker-ce/linux/debian trixie InRelease
Get:2 http://mirror.nju.edu.cn/kali kali-rolling InRelease [34.0 kB]
Get:3 http://mirror.nju.edu.cn/kali kali-rolling/main amd64 Packages [21.6 MB]
Fetched 21.6 MB in 3s (8054 kB/s)
Reading package lists...
六、install 安装
1. 多包安装
apt-get install -y htop tree
Unpacking htop (3.5.3-1) ...
Selecting previously unselected package tree.
Preparing to unpack .../tree_2.3.2-1_amd64.deb ...
Unpacking tree (2.3.2-1) ...
Setting up libunwind8:amd64 (1.8.1-0.4) ...
Setting up tree (2.3.2-1) ...
Setting up htop (3.5.3-1) ...
Processing triggers for libc-bin (2.43-6) ...
💡 Kali Rolling 仓库中的 htop 为 3.5.3-1、tree 为 2.3.2-1(滚动发布,版本随仓库不断更新)。
2. 指定版本安装
apt list -a htop
apt-get install -y htop=3.5.3-1
Listing...
htop/kali-rolling,now 3.5.3-1 amd64 [installed]
💡 按
包名=版本指定版本;与已装版本一致时提示htop is already the newest version。
3. --no-install-recommends 精简安装
apt-get install -y --no-install-recommends <包名>
💡 不装 Recommended 推荐依赖,适合最小化环境。
七、remove / purge / autoremove 卸载
1. remove 卸载(保留配置文件)
apt remove -y tree
(Reading database ... 13822 files and directories currently installed.)
Removing tree (2.3.2-1) ...
2. purge 彻底清除(含配置文件)
apt-get purge -y htop
After this operation, 600 kB disk space will be freed.
(Reading database ... 13814 files and directories currently installed.)
Removing htop (3.5.3-1) ...
3. autoremove 清理孤儿依赖
apt autoremove -y
Freed space: 212 kB
(Reading database ... 13798 files and directories currently installed.)
Removing libunwind8:amd64 (1.8.1-0.4) ...
Processing triggers for libc-bin (2.43-6) ...
💡 htop 卸载后其依赖
libunwind8变为孤儿依赖,autoremove 自动将其移除。
八、list / info / show 查询
1. dpkg -l 列出已装包
dpkg -l | grep -E "docker-ce|containerd"
ii containerd.io 2.3.3-1~debian.13~trixie amd64 ...
ii docker-ce 5:29.7.2-1~debian.13~trixie amd64 ...
ii docker-ce-cli 5:29.7.2-1~debian.13~trixie amd64 ...
ii docker-ce-rootless-extras 5:29.7.2-1~debian.13~trixie amd64 ...
💡 第一列
ii表示已安装;rc表示已卸载但保留配置。
2. apt show 查看仓库信息
apt show htop
Package: htop
Version: 3.5.3-1
Priority: optional
Section: utils
Maintainer: Daniel Lange <DLange@debian.org>
Installed-Size: 600 kB
Depends: libc6 (>= 2.38), libncursesw6 (>= 6), libtinfo6 (>= 6), libunwind8
Suggests: libnl-3-200, libnl-genl-3-200, lm-sensors, lsof, strace
Homepage: https://htop.dev/
3. apt-cache policy 查看候选版本
apt-cache policy docker-ce
docker-ce:
Installed: 5:29.7.2-1~debian.13~trixie
Candidate: 5:29.7.2-1~debian.13~trixie
Version table:
*** 5:29.7.2-1~debian.13~trixie 500
500 https://mirrors.aliyun.com/docker-ce/linux/debian trixie/stable amd64 Packages
100 /var/lib/dpkg/status
5:29.7.1-1~debian.13~trixie 500
💡
policy显示已装版本、候选版本与来源仓库,升级前可用它确认可获取的版本。
九、clean / 缓存管理
du -sh /var/cache/apt/archives
apt clean
apt autoclean
12K /var/cache/apt/archives
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
💡
apt clean清空全部缓存无输出;apt autoclean只清理不再需要的旧版本 .deb。
十、历史记录与升级(history / upgrade / dist-upgrade)
1. 操作历史
tail -12 /var/log/apt/history.log
Start-Date: 2026-10-07 11:08:46
Commandline: apt-get purge -y htop
Purge: htop:amd64 (3.5.3-1)
End-Date: 2026-10-07 11:08:47
Start-Date: 2026-10-07 11:08:48
Commandline: apt autoremove -y
Remove: libunwind8:amd64 (1.8.1-0.4)
End-Date: 2026-10-07 11:08:48
2. 查看可升级包
apt list --upgradable
Listing...
💡 实测当前仓库无可升级包(输出只有
Listing...),存在可升级包时此处列出包名/仓库 新版本 [upgradable from: 旧版本]。
3. upgrade 普通升级
apt-get upgrade -y
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
💡
upgrade只升级已有包,不安装新依赖、不卸载冲突包。
4. dist-upgrade 智能升级
apt-get dist-upgrade -y
Reading state information...
Calculating upgrade...
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
💡
dist-upgrade升级时处理依赖变化(安装/删除)。apt 对应的交互命令为apt upgrade。
十一、离线 deb 安装实测(dpkg -i 与依赖修复)
离线机把 .deb 拷入后执行 dpkg -i。实测用 apt-get download toilet 下载后直接安装,出现依赖缺失:
cd /var/cache/kali-debs
apt-get download toilet
dpkg -i toilet*.deb
W: Download is performed unsandboxed as root as file '/var/cache/kali-debs/toilet_0.3-6_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
Preparing to unpack toilet_0.3-6_amd64.deb ...
Unpacking toilet (0.3-6) ...
dpkg: dependency problems prevent configuration of toilet:
toilet depends on toilet-fonts; however:
Package toilet-fonts is not installed.
toilet depends on libcaca0 (>= 0.99.beta20); however:
Package libcaca0 is not installed.
dpkg: error processing package toilet (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
toilet
⚠️ 实测:
dpkg -i不解析依赖,报toilet depends on toilet-fonts / libcaca0属正常现象。补齐依赖后修复:
apt-get install -f -y
Reading package lists...
Building dependency tree...
Reading state information...
Solving dependencies...
Setting up mesa-libgallium:amd64 (26.1.6-1) ...
Setting up libgbm1:amd64 (26.1.6-1) ...
Setting up libgl1-mesa-dri:amd64 (26.1.6-1) ...
Setting up libglut3.12:amd64 (3.4.0-6+b2) ...
Processing triggers for libc-bin (2.43-6) ...
dpkg -l toilet | tail -1
ii toilet 0.3-6 amd64 display large colourful characters in text mode
💡 离线环境需提前用
apt-get download把依赖闭包一并下载携带(如 docker-ce 离线包场景),联网环境直接apt-get install -f自动补装。
十二、常见问题与真实行为
-
apt search 结果太多:全文搜索按描述匹配,想按包名精确搜用
apt-cache search或apt list -a。 -
remove 后包仍占用空间:remove 保留配置文件,需
purge彻底清除;孤儿依赖需autoremove清理。 -
dpkg -i报依赖缺失:dpkg 不做依赖解析,执行apt-get install -f修复,或提前把依赖 deb 一起dpkg -i。 -
http.kali.org重定向:官方轮询域名会自动跳到国内镜像(实测命中mirror.nju.edu.cn),若下载慢可手动改kali.sources的URIs为阿里云等国内镜像。 -
apt 与 apt-get 命令对应:
apt为交互优化版(update/install/remove/purge/autoremove/list/show/search/upgrade);apt-get更稳定适合脚本(update/install/remove/purge/autoremove/upgrade/dist-upgrade/download)。两者读取同一套源配置,无功能差异。
十三、命令与参数速查表
| 命令 | 作用 | 常用参数 |
|---|---|---|
| apt-get update | 刷新软件包索引 | - |
| apt-get install | 安装包 | -y 免确认;包名=版本 指定版本;--no-install-recommends 精简安装 |
| apt-get remove | 卸载(保留配置) | -y |
| apt-get purge | 卸载并清除配置 | -y |
| apt autoremove | 清理孤儿依赖 | -y |
| apt-get upgrade | 升级已有包 | -y |
| apt-get dist-upgrade | 智能升级(处理依赖变化) | -y |
| apt-get install -f | 修复损坏依赖 | - |
| apt search / apt-cache search | 搜索包 | - |
| apt list | 列出包 | --installed / -a 所有版本 / --upgradable |
| apt show / apt-cache show | 查看包详情 | - |
| apt-cache policy | 查看候选版本与来源 | - |
| apt clean / autoclean | 清理缓存 | - |
| dpkg -i / -r / --purge | 底层安装/卸载/清除 | - |
| dpkg -s / -l / -L | 查状态/列表/文件清单 | - |
| apt-get download | 仅下载 deb 不安装(离线用) | - |