Given a list of dev packages (e.g. pkgs="python3.5-dev python3-tk"), would there be a difference between running
sudo apt-get install $pkgs
vs.
for p in $pkgs; do sudo apt-get install $p; done
I'm asking mostly dependencies-topo-sort related, i.e. will there be different packages downloaded and installed in either way
Yes, different packages can be selected to satisfy dependencies. Running 1 command that specifies N packages to be installed will sometimes have a different effect from running N commands each of which specifies 1 package to be installed, even when the actual packages specified are the same in each case.
The main practical difference is probably the one karel has described. However, the effects can differ even when all operations succeed, due to different dependency resolution.
The reason is as you broadly surmised:
More specifically, this happens because there can be more than one alternative that satisfies a dependency.
Abstract Explanation
Suppose you wish to install package
a
, which depends on a virtual packagev
, andv
can be satisfied by packageb
or packagec
and in no other way. Supposeb
does not depend onc
,c
does not depend onb
, and none of those packages are installed already. Now suppose you run:Then APT will select
b
orc
to satisfy the dependency. Which one it picks is the result of a computation it performs that may be affected by what packages you have installed, what packages are available, what version of APT you are using, and how it is configured. But when all these conditions are the same, the decision will be made the same each time.Suppose without loss of generality that it picks
b
. Thena
andb
are installed. Suppose you then run:After that,
a
,b
, andc
are all installed. That is, all three packages were installed as a result of running:In contrast, suppose you were to run this command instead of those:
Then, since
a
's dependency onv
is satisfied byc
,b
is not installed. That is, onlya
andc
, but notb
, are installed as a consequence of running:Concrete Example
You can find concrete examples of this by running
apt
orapt-get
with the-s
option, which causes it to simulate your action rather than performing it. (Just remember that you cannot fully confirm them just withapt-get -s
/apt -s
, because earlierapt-get -s
/apt -s
commands do not affect later ones, since they do not affect anything, since they are only simulations.)Running
sudo apt-get install jedit
on my Ubuntu 16.04 LTS system would install several OpenJDK 8 packages:If I told APT to install both
jedit
andopenjdk-9-jre
by runningsudo apt-get install jedit openjdk-9-jre
, then it wouldn't install OpenJDK 8 packages, becausejedit
's dependency on a Java runtime is satisfied by OpenJDK 9 packages:If I installed
jedit
andopenjdk-9-jre
with two separatesudo apt-get install
commands, issued in that order, then I would get both OpenJDK 8 and OpenJDK 9 packages.If even one package from a very long list of packages can't be installed, then the execution of the command will stop and it will print an informative error message. It can also be frustrating to install a long list of packages in one batch because some of the packages will require interactive user input in the terminal in order to be installed successfully. If you make a mistake in the user input then you will have to restart the entire installation process from the beginning.
It's difficult to get the command to execute successfully until the end unless you split the initial long list of packages into groups of 25-40 packages and then install the packages with apt one group at a time. This doesn't take much extra time, and makes installing all of the packages easier to manage.
Just remember one more thing.
sudo apt install
locks the administrative directory (/var/lib/dpkg/
) when it is running, so don't run any other process that requires root privileges until apt completely finishes processing. For example if you are installing packages with apt from the terminal, don't try to install other snap packages from the terminal in a new tab or window until apt finishes processing.