Example: https://packages.ubuntu.com/bionic/php7.2

php package depends on one of:

  • libapache2-mod-php7.2
  • php7.2-fpm
  • php7.2-cgi

Running sudo apt install php always installs the first of these dependencies, unless one of the others has been installed already. Even running sudo apt install php php-cli installs the first dependency.

How can I select e.g. php-cgi in one go ?

So instead of

sudo apt install php-cgi && sudo apt install php

I want something like

sudo apt install --select-dependency php-cgi php

Please note that php is just an example, I'm looking for a general answer.

1 Answer 1


You can provide multiple arguments to apt install to dictate which packages you want to install in one go - this is so automated installation scripts and such as well as users can install all the defined packages in a single go rather than trying to do it one by one by one.

The general syntax is this:

sudo apt install package1 package2 package3 package4 ...

How the various packages behave with this will vary based on the package and its dependencies.

But in the case of php its its own hell to install because in SOME cases apt is stupid when resolving the dependencies, so if you need php-cli just install it and only it:

sudo apt install php-cli

Same behavior for php-fpm too or php-cgi - just install it, it'll pull in the common dependencies it needs.

  • @pLumo Correction: apt is stupid with metapackage deps. THIS SAID you only need to install php-cli to get php CLI interface, it does not need the rest of php to work this way. And as I stated already, how apt handles this will be entirely dependent on the packages, its dependencies, and any metapackage dependency evils that are involved. Since you asked for a "general" solution I gave you a general solution.
    – Thomas Ward
    Jul 23, 2019 at 15:19
  • sure, php-cli depends on php, that is clever ;-)
    – pLumo
    Jul 23, 2019 at 15:19
  • @pLumo actually, it doesn't depend on the php metapackage at all; see paste.ubuntu.com/p/YdMbk8jvrN for the dep chain on 18.04 as an example. It pulls in php7.2-common which is the 'common' php bits common to all PHP drivers.
    – Thomas Ward
    Jul 23, 2019 at 15:21
  • cgi vs cli was a typo-kind of problem of my side. But sudo apt install php php-cgi vs sudo apt install php php7.2-cgi nailed it. Maybe you can add this information to the answer ... that apt does not resolve dependencies when deciding that...
    – pLumo
    Jul 23, 2019 at 15:24

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.