How can I reinstall all packages that are dependencies of a package I installed? The package does not want to run due to an install problem. A dependency may have been installed but does not work, dpkg-reconfigure -a does not work. Is there a terminal command to reinstall all of a package's dependencies without reinstalling all packages.


You need a bit of text processing to feed the actual command to apt-get. The following should do :

sudo apt-get install --reinstall $(apt-cache depends package | \
     grep -Po 'Depends:\s+\K[^ ]+$' | tr '\n' ' ')

Replace package with the actual package name. You can also do a --dry-run before proceeding to be sure of the actions.

It has couple of parts :

  • apt-cache depends package will find the dependencies of package

  • grep -Po 'Depends:\s+\K[^ ]+$ | tr '\n' ' '' will get us only the name of the dependencies in a space separated form

  • So the command substitution pattern $(apt-cache depends vim | grep -Po 'Depends:\s+\K[^ ]+$' | tr '\n' ' ') will feed the name of the packages to apt-get install --reinstall.

Example using vim :

$ apt-cache depends vim | grep -Po 'Depends:\s+\K[^ ]+$'

$ 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])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.