14

When I run the following:

sudo apt-get install vim abcde php5-cli

It fails with the following message which is the expected behavior:

E: Unable to locate package abcde`.

I want it to install vim and even if there is an error on abcde just continue to install php5-cli package. Meaning I want apt-get to continue down the list, even if it can not find some of the packages.

I've tried:

sudo apt-get install --ignore-missing vim abcde php5-cli
11

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.

1
  • By the way, if you're someone like me who uses Fish instead of Bash, you'll first need to type "bash" to switch shells. Then copy and paste the command since for some reason it will not work the Fish shell. Works fine with Bash. – Ev- Apr 25 '16 at 6:04
1

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
1

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. :)

1

I've come up with a function that allows to install a bunch of packages and leave out the ones that are not available and could break the complete install.

install_aval_package() {
for i in $1
  do 
     if [ -z "$(apt-cache madison $i 2>/dev/null)" ]; then
       echo " > Package $i not available on repo."
     else
       echo " > Add package $i to the install list"
     packages="$packages $i"
     fi
 done
 echo "$packages" #you could comment this.
 apt-get -y install $packages
}

Using it like this,

install_aval_package "bmon curl dialog git htop language-pack-en-base molly-guard nano net-tools ntp openssh-server software-properties-common ssh sudo wget whiptail bmon curl dialog git htop language-pack-en-base molly-guard nano net-tools ntp openssh-server software-properties-common ssh sudo wget whiptail"

Or like this,

install_aval_package "bmon \
                  curl \
                  dialog \
                  git \
                  htop \
                  language-pack-en-base \
                  molly-guard \
                  nano \
                  net-tools \
                  ntp \
                  openssh-server \
                  software-properties-common \
                  ssh \
                  sudo \
                  wget \
                  whiptail"

Where the output in this case have all the requested packages on the repositories,

 > Add package bmon to the install list
 > Add package curl to the install list
 > Add package dialog to the install list
 > Add package git to the install list
 > Add package htop to the install list
 > Add package language-pack-en-base to the install list
 > Add package molly-guard to the install list
 > Add package nano to the install list
 > Add package net-tools to the install list
 > Add package ntp to the install list
 > Add package openssh-server to the install list
 > Add package software-properties-common to the install list
 > Add package ssh to the install list
 > Add package sudo to the install list
 > Add package wget to the install list
 > Add package whiptail to the install list
 bmon curl dialog git htop language-pack-en-base molly-guard nano net-tools ntp openssh-server software-properties-common ssh sudo wget whiptail bmon curl dialog git htop language-pack-en-base molly-guard nano net-tools ntp openssh-server software-properties-common ssh sudo wget whiptail
Reading package lists... Done
Building dependency tree       
Reading state information... Done
etc....

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.