运行sudo apt-get install <PACKAGE>
将安装该包、其依赖项以及任何其他推荐的包。
但是,似乎没有办法安装仅有的包的依赖关系并排除包本身。
怎样才能做到这一点?
答案1
这将安装包中的所有包依靠和预依赖场地:
sudo apt-get install $(apt-cache depends <PACKAGE> | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ')
基本上你要求所有的依赖项,过滤掉(预)取决于,并格式化 apt-get 的输出。
一个问题是依赖关系
Depends: pulseaudio
pulseaudio:i386
或类似的虚拟包
Depends: <java6-runtime-headless>
default-jre-headless
openjdk-6-jre-headless
所以:小心使用——它并不在所有情况下都有效!
答案2
如果您不介意复制/粘贴,只需使用 模拟 apt-get 安装-s
。这样,您将看到哪些其他软件包将被安装和/或升级,然后您只需从该列表中删除您不想安装的软件包名称即可。
sudo apt-get install -s <package>
答案3
要列出未安装的给定包的所有依赖项,您可以使用aptitude
aptitude search '!~i?reverse-depends("^PACKAGE_NAME$")'
安装依赖项
aptitude search '!~i?reverse-depends("^PACKAGE_NAME$")' -F "%p" | xargs sudo apt-get install
例子
列出依赖项
% aptitude search '!~i?reverse-depends("^mc$")' p mc-data - Midnight Commander - a powerful file manager -- data files
仅显示包名称
% aptitude search '!~i?reverse-depends("^mc$")' -F "%p" mc-data
安装依赖项,例如
mc
% aptitude search '!~i?reverse-depends("^mc$")' -F "%p" | xargs sudo apt-get install Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: mc-data 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 1.166 kB of archives. After this operation, 5.550 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ wily/universe mc-data all 3:4.8.13-3 [1.166 kB] Fetched 1.166 kB in 0s (1.250 kB/s) Selecting previously unselected package mc-data. (Reading database ... 606748 files and directories currently installed.) Preparing to unpack .../mc-data_3%3a4.8.13-3_all.deb ... Unpacking mc-data (3:4.8.13-3) ... Processing triggers for doc-base (0.10.6) ... Processing 1 added doc-base file... Registering documents with scrollkeeper... Processing triggers for man-db (2.7.4-1) ... Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ... Setting up mc-data (3:4.8.13-3) ...
答案4
您可以解析 apt install 模拟的输出来执行此操作,这里有一个 bash 函数可以为您执行此操作:
apt-install-depends() {
local pkg="$1"
apt-get install -s "$pkg" \
| sed -n \
-e "/^Inst $pkg /d" \
-e 's/^Inst \([^ ]\+\) .*$/\1/p' \
| xargs apt-get install
}
用法:
apt-install-depends mopidy