当前位置: 首页>>技术问答>>正文


如何只安装包的依赖项?

, ,

问题描述

运行sudo apt-get install <PACKAGE>将安装程序包,其依赖项以及任何其他推荐的程序包。

但是,似乎没有办法只安装包的依赖项并排除包本身。

怎么会这样做呢?

最佳解决思路

这将在包的Depends和PreDepends字段中安装所有包:

sudo apt-get install $(apt-cache depends <PACKAGE> | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ')

基本上你要求所有依赖项,过滤掉(Pre)Depends,并格式化apt-get的输出。

一个问题是依赖性

Depends: pulseaudio
  pulseaudio:i386

或虚拟包

Depends: <java6-runtime-headless>
  default-jre-headless
  openjdk-6-jre-headless

所以:小心使用 – 它并不适用于所有情况!

次佳解决思路

如果您不介意复制/过去,只需使用-s模拟apt-get安装。这样您就会看到哪些其他软件包将被安装和/或升级,然后您只需从该列表中删除您不想安装的软件包名称即可。

sudo apt-get install -s <package>

第三种解决思路

apt-get build-dep <package>将成功。

第四种思路

要列出未安装的给定程序包的所有依赖项,可以使用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) ...
    

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/2643.html,未经允许,请勿转载。