drush cc all
works, but this:
sudo drush cc all
sudo: drush: command not found
Why? How to fix this?
sudo, you get a preconfigured
$PATH, which is (supposed to be) something like the root user's default path. Your program is not in that list of directories identified by
See for example
sudo tries to be safe when executing external commands.
There are two distinct ways to deal with environment variables. By default, the
env_resetsudoers option is enabled. This causes commands to be executed with a minimal environment containing
USERNAMEin addition to variables from the invoking process permitted by the
env_keepsudoers options. There is effectively a whitelist for environment variables.
If you cannot configure
sudo to preserve your
$PATH, the usual workaround is to specify the complete pathname of the program. That may not work well with scripts that call other executables in the (not-accessed) directory.
You should specify the full path. It's also more secure; it you don't specify the path, it's conceivable that an attacker could create another program that will be run with root permissions.
Also, you need to put a line in
/etc/sudoers to allow it.
man sudoers for the syntax, it's way too much to put here.