0

I tried to uninstall PHP but I got the following error instead. What does this error mean and how to solve it?

$ sudo apt-get remove --purge php*
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package php-7-v-podlinnike.pdf
E: Couldn't find any package by glob 'php-7-v-podlinnike.pdf'
E: Couldn't find any package by regex 'php-7-v-podlinnike.pdf'
Raffa
  • 34,963

1 Answers1

1

It appears that the unquoted php* is expanded by your shell to a filename(php-7-v-podlinnike.pdf) that exists in your current working directory ... In which case, the expansion will happen before the package name/name pattern is passed to apt-get ... Therefore all apt-get will see in this case is php-7-v-podlinnike.pdf and not php* ... You can run set -x(to enable printing command debugging/execution) in your terminal then run your command to see that what is actually passed to apt-get looks like this:

apt-get remove --purge php-7-v-podlinnike.pdf

and not:

apt-get remove --purge php*

as you might think.

You can prevent that expansion by quoting it(i.e. either "php*" or 'php*') ... Note that single quotes '...' can be safer in this case as noted by @Thomas Ward.

Also, your assumption of apt-get using the globbing pattern to match any package starting with php in its name might not be always correct/safe ... apt-get seems to, sometimes, might handle that as a regular expression and not a globbing pattern ... As you see in your case apt-get tried both by glob and by regex:

E: Couldn't find any package by glob 'php-7-v-podlinnike.pdf'
E: Couldn't find any package by regex 'php-7-v-podlinnike.pdf'

So, you might want to use something like '^php.*' instead as a safer alternative.

I would, however, advice you to be very cautious when mass removing packages and carefully read the list of packages to be removed before answering yes to action/s suggested by apt-get ... See for example apt-get remove with wildcard removed way more than expected. why?.

Also, as a side note, if you exclude the --purge option, packages will still be removed but configuration files will be saved in case you decide to reinstall a certain package later so it will use those configuration files(so it behaves the same way it used to before you remove it) instead of starting from scratch.

You can also use the -s option to simulate the result of your apt-get command without actually removing any package like so:

apt-get -s remove 'php*'
Raffa
  • 34,963