在 Debian / Ubuntu 等系统中,“提取依赖包”通常有以下几种常见需求。我按不同场景给你说明,并附上常用命令。
apt-cache depends 包名
示例:
apt-cache depends nginx
更详细(含推荐、建议):
apt-cache depends --recurse nginx
apt-cache rdepends 包名
示例:
apt-cache rdepends libssl3
apt-get download(推荐)只下载 .deb,不安装:
apt-get download 包名
下载某个包及其所有依赖:
apt-get install --download-only --reinstall -o Dir::Cache::archives=/tmp/debs 包名
示例:
mkdir /tmp/debs
apt-get install --download-only --reinstall -o Dir::Cache::archives=/tmp/debs curl
apt-rdepends(递归依赖)先安装:
sudo apt install apt-rdepends
然后:
apt-rdepends 包名 | grep -v "^ " | sort -u
下载所有依赖:
apt-rdepends 包名 | grep -v "^ " | xargs apt-get download
⚠️ 注意:可能包含已安装包,需自行过滤。
.deb 文件/var/cache/apt/archives/ 提取ls /var/cache/apt/archives/ | grep 包名
复制出来:
cp /var/cache/apt/archives/包名*.deb /tmp/
dpkg-repack 包名
安装工具:
sudo apt install dpkg-repack
.deb 文件(提取内容)如果你是想解压依赖包内容:
dpkg -x 包名.deb 目录
只解压控制信息:
dpkg -e 包名.deb 目录/DEBIAN
apt-get install --download-only 包名
dpkg -i *.deb
或:
apt install ./包名.deb
| 需求 | 命令 |
|---|---|
| 查看依赖 | apt-cache depends 包名 |
| 查看被谁依赖 | apt-cache rdepends 包名 |
| 下载但不安装 | apt-get download 包名 |
| 下载所有依赖 | apt-get install --download-only 包名 |
| 解包 deb | dpkg -x xxx.deb dir |
| 离线安装 | dpkg -i *.deb |
如果你能具体说明:
我可以给你更精确的方案(比如最小依赖、交叉环境、Docker 场景)。