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.

4 Answers 4


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.

  • 2
    Note that --ignore-missing only workarounds for an issue in download. See superuser.com/a/844627/106974
    – IsaacS
    Apr 5, 2016 at 20:22
  • 11
    This actually does not work.
    – leoheck
    Jun 3, 2016 at 17:58
  • 1
    Why is this selected? It does not work.
    – Akito
    Sep 15, 2021 at 11:22
  • -m, --fix-missing, --ignore-missing do not seem to work anymore. The package manager just stops when it can't find a package. Tested on Ubuntu 23.04 and 22.10
    – Artichoke
    Apr 27, 2023 at 9:19
for i in package1 package2 package3; do
  sudo apt-get install $i
  • 6
    A bit brutal performance wise (package dependency tree is being built from the scratch for every iteration), but should work fine. May 3, 2011 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, 2017 at 12:36

Here's a solution that actually works (unlike the accepted answer) and which addresses the performance issue of the correct answer:

Before invoking apt install, filter non-existent packages out of the list. The list of installable packages can be obtained by running apt-cache --generate pkgnames, which we then grep for the packages we want to install, and xargs the result into apt install. The full command looks like this:

apt-cache --generate pkgnames \
| grep --line-regexp --fixed-strings \
  -e package1 \
  -e package2 \
  -e package3 \
  … \
| xargs apt install -y
  • The main requirement is to duplicate on another machine so a solution utilising a catalogue from the machine you're duplicating would be nice. Why are you hard coding package names here?? But agreed, I never got any of these solutions to work in the real world.
    – RichieHH
    May 5, 2021 at 7:03
  • 1
    @RichieHH The question is literally "how to make sudo apt-get install package1 package2 package3 not fail when one of packageN does not exist?" and so that's what my answer answers. May 5, 2021 at 9:08

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
  • @Fabby I've edited the text to make it explicit for your satisfaction
    – Chenna V
    Jan 23, 2017 at 0:43
  • 2
    That looks more like an edit to the existing answer here than a new answer. ¯\_(ツ)_/¯ Sorry! -1...
    – Fabby
    Jan 23, 2017 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .