23

I am making a bash script that installs various packages using apt-get install. However, I notice that if there is a line that says:

sudo apt-get install package1 package2 package3

and either of the packages is not found, none of the others will be installed. How do I make it keep going even if it can't find one of the packages?

Thanks in advance.

17

I suggest an apt-get option

sudo apt-get --ignore-missing install $list_of_packages

but be aware that missing dependences cannot be ignored, and even if you use --force you can get a broken system.

6
for i in package1 package2 package3; do
  sudo apt-get install $i
done
  • 4
    A bit brutal performance wise (package dependency tree is being built from the scratch for every iteration), but should work fine. – Serge Broslavsky May 3 '11 at 5:53
  • As @blueskin alluded to, using the -y option would be good if you didn't want to interact with it, especially when installing a massive list of packages. – pd12 May 8 '17 at 12:36
0

Install each package as a separate command rather than in a single command, this way if one fails to install either due to not found or some other error then it won't stop the others from installing. For which you can use 'for' loop as below. Also, remember to use the -y flag if installing a lot of packages, to avoid the mayhem of typing yes for each one.

INSTALL_PKGS="pk1 pk2 pk3 pk4 pk5 ... and so ... on ..pk_gogol"
for i in $INSTALL_PKGS; do
  sudo apt-get install -y $i
done
  • @Fabby I've edited the text to make it explicit for your satisfaction – blueskin Jan 23 '17 at 0:43
  • 1
    That looks more like an edit to the existing answer here than a new answer. ¯\_(ツ)_/¯ Sorry! -1... – Fabby Jan 23 '17 at 14:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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