Continue on error when apt-get encounters an install unable to locate package issue

Short answer: It is possible that you actually do not want to do this.

Why is that? There has been a lot of discussion on this particular functionality. One such is in this (duplicate)bug report and the one it is linked to.

Discussion at the bug report also explains that "--ignore-missing" only applies if the there is an issue downloading a package that should otherwise exist by the information your ´apt-get´ has. This is also explained here and in the documentation.

Is there a workaround?

If after reading the previous sources you are still very sure you want to do this then, on the other hand, there are (suboptimal but rather safe) options like the one specified by user "Aleksandr Levchuk" here:

for i in package1 package2 package3; do
  sudo apt-get install $i
done

Or if you prefer then a one-liner with minimal modification:

for i in package1 package2 package3; do sudo apt-get install $i; done

If there're a lot of packages, you can add -y so it won't ask for confirmation repeatedly:

for i in package1 package2 package3; do
  sudo apt-get install -y $i
done

Or:

for i in package1 package2 package3; do sudo apt-get install -y $i; done

Hope this helps.


While the other answers do work, performing a separate install call per package has a few issues:

  • It removes a lot of the points/strength of apt and its ability to determine which packages would share dependencies or clash ahead of time
  • If sudo is required (usually), then the sudo timeout can be reached before all packages are installed

Recently I came across this issue as I was moving a personal machine over from one Ubuntu 18.04 (Bionic) install to another newer clean version of Ubuntu 20.04 (Focal), but wanted to install the same packages on the new machine... and I came up with a nice solution:

I started with a file containing a list generated from the old machine, which had each package name on its own separate line, easily generated by the following:

apt list --installed 2>/dev/null | sed 's/\/.*//g > packages'

I then ran the file list through apt to filter the list down to all packages that were available on the newer machine/repo and that weren't virtual, while piping the results to another file, echoing the progress, and the ultimately installing the resulting packages:

# Filter packages for those available
while read package; do apt show "$package" 2>/dev/null | grep -qvz 'State:.*(virtual)' && echo "$package" >>packages-valid && echo -ne "\r\033[K$package"; done <packages

# Install the available packages all at once
sudo apt install $(tr '\n' ' ' <packages-valid)

And that worked!

Hopefully this finds someone else well. :)


One way to circumvent this is to invoke apt-get once for each package:

echo package1 package2 package3 | xargs -n 1 sudo apt-get install -y

Or as a function

function install_ignore_fail { echo "$*" | xargs -n 1 sudo apt-get install -y; }

install_ignore_fail package1 package2 package3