7

Sample command:

drush cc all

works, but this:

sudo drush cc all

gives me:

sudo: drush: command not found

Why? How to fix this?

  • I've also had this issue sometimes, with such basic commands as cd. Using dzdo cd returning "command not found". Of course I later realized that cding into a directory that I don't have permissions in, won't help very much, so I either need a root shell or need to dzdo ls, dzdo mv, etc. the contents from outside that dir. – Wildcard Nov 27 '15 at 0:31
  • 2
    The problem with sudo cd is that cd is a built-in command, not a program. If you want to go into a directory that you don't have any access to, and (for example) rename a file there, you could do (for example) sudo mv dir/oldfile dir/newfile or sudo sh -c "cd dir; mv oldfile newfile". – G-Man Nov 27 '15 at 22:39
11

When you 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 $PATH.

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_reset sudoers option is enabled. This causes commands to be executed with a minimal environment containing TERM, PATH, HOME, SHELL, LOGNAME, USER and USERNAME in addition to variables from the invoking process permitted by the env_check and env_keep sudoers 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.

0

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.

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.