8

I am currently installing php7.0 and was wondering if there is an shorter way to install the modules. normally I type:

    apt-get install php7.0 php7.0-fpm php7.0-mbstring php7.0-mcrypt 
     php7.0-phpdbg php7.0-dev php7.0-curl php7.0-sqlite3 php7.0-json 
     php7.0-gd php7.0-cli

Is there an regular expression so you don't have to type php7.0 over and over again? Something like:

   apt-get install php7.0-{fpm mbstring mcrypt phpdbg dev curl sqlite3 
    json gd cli}

I searched for something like this for hours but could not find it. In advance thanks for your reply.

2
  • 1
    What about apt-get install php7*? Short enough? But it will simply install all possible php7 packages.
    – Videonauth
    Jun 12, 2016 at 13:02
  • @Videonauth worse - it will install all packages containing php anywhere in the package name.
    – muru
    Jun 13, 2016 at 19:48

1 Answer 1

14

As @Videonauth suggested, you can use apt-get install php7.* but that will install all packages whose names contain php7. To install those whose names starts with php7, use apt-get install '^php7. *. To instal only those on your list, you can use brace expansion. The format is almost what you already tried: braces but a comma-separated list:

$ echo foo{a,b,c}
fooa foob fooc

Therefore:

$ echo php7.0-{fpm,mbstring,mcrypt,phpdbg,dev,curl,sqlite3,json,gd,cli}
php7.0-fpm php7.0-mbstring php7.0-mcrypt php7.0-phpdbg php7.0-dev php7.0-curl php7.0-sqlite3 php7.0-json php7.0-gd php7.0-cli

So, you could run:

sudo apt-get install php7.0-{fpm,mbstring,mcrypt,phpdbg,dev,curl,sqlite3,json,gd,cli}
6
  • He he, wasn't sure about if those brace expansions will work, so I only commented.
    – Videonauth
    Jun 12, 2016 at 13:09
  • @Videonauth yup, they do, they just need space. You can also do things like echo {1..10} or echo {01..10}. Useful stuff.
    – terdon
    Jun 12, 2016 at 13:09
  • No, php7* does not install packages starting with php7. apt-get uses regular expressions, not wildcards. Unless you have files named php7-foo in your current directory, php7* will be passed by the shell to apt-get, which will treat it as a regex and match it over the entire package name. So every package containing php in its name will be selected for installation. People have been bit by this, repeatedly: askubuntu.com/questions/210976/…
    – muru
    Jun 15, 2016 at 0:38
  • @muru eek! Thanks, I'd forgotten the ..
    – terdon
    Jun 15, 2016 at 7:40
  • @terdon not just the ., you'll need to anchor the expression with ^
    – muru
    Jun 15, 2016 at 7:41

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.