如何重新安装我安装的软件包的所有依赖包?由于安装问题,软件包无法运行。依赖包可能已安装但不起作用dpkg-reconfigure -a
。是否有终端命令可以重新安装软件包的所有依赖包,而无需重新安装所有软件包。
答案1
您需要进行一些文本处理才能将实际命令提供给apt-get
。以下应该可以做到:
sudo apt-get install --reinstall $(apt-cache depends package | \
grep -Po 'Depends:\s+\K[^ ]+$' | tr '\n' ' ')
替换package
为实际的包名称。您还可以--dry-run
在继续操作之前执行以确保操作正确。
它有几个部分:
apt-cache depends package
将会找到依赖项package
grep -Po 'Depends:\s+\K[^ ]+$ | tr '\n' ' ''
将只获取以空格分隔的依赖项名称因此命令替换模式
$(apt-cache depends vim | grep -Po 'Depends:\s+\K[^ ]+$' | tr '\n' ' ')
将把包的名称提供给apt-get install --reinstall
。
使用示例vim
:
$ apt-cache depends vim | grep -Po 'Depends:\s+\K[^ ]+$'
vim-common
vim-runtime
libacl1
libc6
libgpm2
libpython2.7
libselinux1
libtinfo5
$ sudo apt-get install --dry-run --reinstall $(apt-cache depends vim | grep -Po 'Depends:\s+\K[^ ]+$' | tr '\n' ' ')
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libc-dev-bin libc6:i386 libc6-dbg libc6-dev libpython2.7-minimal
libpython2.7-stdlib python2.7 python2.7-minimal
Suggested packages:
glibc-doc glibc-doc:i386 locales:i386 python2.7-doc
The following packages will be upgraded:
libc-dev-bin libc6 libc6:i386 libc6-dbg libc6-dev libpython2.7
libpython2.7-minimal libpython2.7-stdlib python2.7 python2.7-minimal
10 upgraded, 0 newly installed, 6 reinstalled, 0 to remove and 506 not upgraded.
Inst libc-dev-bin [2.19-0ubuntu6.5] (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64]) [libc6-dev:amd64 ]
Inst libc6-dev [2.19-0ubuntu6.5] (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64]) []
Inst libc6-dbg [2.19-0ubuntu6.5] (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64]) []
Inst libc6 [2.19-0ubuntu6.5] (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64]) [libc6:amd64 on libc6:i386] [libc6:i386 on libc6:amd64] [libc6:i386 ]
Inst libc6:i386 [2.19-0ubuntu6.5] (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [i386])
Inst libacl1 [2.2.52-1] (2.2.52-1 Ubuntu:14.04/trusty [amd64])
Conf libc6 (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64])
Conf libc6:i386 (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [i386])
Conf libacl1 (2.2.52-1 Ubuntu:14.04/trusty [amd64])
Inst libselinux1 [2.2.2-1ubuntu0.1] (2.2.2-1ubuntu0.1 Ubuntu:14.04/trusty-updates [amd64])
Conf libselinux1 (2.2.2-1ubuntu0.1 Ubuntu:14.04/trusty-updates [amd64])
Inst libtinfo5 [5.9+20140118-1ubuntu1] (5.9+20140118-1ubuntu1 Ubuntu:14.04/trusty [amd64])
Conf libtinfo5 (5.9+20140118-1ubuntu1 Ubuntu:14.04/trusty [amd64])
Inst libgpm2 [1.20.4-6.1] (1.20.4-6.1 Ubuntu:14.04/trusty [amd64])
Inst python2.7 [2.7.6-8] (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64]) []
Inst python2.7-minimal [2.7.6-8] (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64]) []
Inst libpython2.7 [2.7.6-8] (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64]) []
Inst libpython2.7-stdlib [2.7.6-8] (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64]) []
Inst libpython2.7-minimal [2.7.6-8] (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
Inst vim-common [2:7.4.052-1ubuntu3] (2:7.4.052-1ubuntu3 Ubuntu:14.04/trusty [amd64])
Inst vim-runtime [2:7.4.052-1ubuntu3] (2:7.4.052-1ubuntu3 Ubuntu:14.04/trusty [all])
Conf libc-dev-bin (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64])
Conf libc6-dev (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64])
Conf libc6-dbg (2.19-0ubuntu6.6 Ubuntu:14.04/trusty-updates [amd64])
Conf libgpm2 (1.20.4-6.1 Ubuntu:14.04/trusty [amd64])
Conf libpython2.7-minimal (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
Conf python2.7-minimal (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
Conf libpython2.7-stdlib (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
Conf python2.7 (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
Conf libpython2.7 (2.7.6-8ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
Conf vim-common (2:7.4.052-1ubuntu3 Ubuntu:14.04/trusty [amd64])
Conf vim-runtime (2:7.4.052-1ubuntu3 Ubuntu:14.04/trusty [all])