How to apt-get install multiple packages without stopping (if not found)?

Solution 1:

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.

Solution 2:

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

Solution 3:

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

Solution 4:

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