This question already has an answer here:

Platform: Ubuntu 10.04 VM running out of VirtualBox

File details:

-rwxr-x---  1 myuser myuser  123 2013-10-31 16:10 myscript.sh

The executable is visible in the directory:

>type myscript.sh
myscript.sh is ./myscript.sh

I do have . in the path:

>echo $PATH

Running it without sudo works fine:


but not with sudo:

>sudo myscript.sh
sudo: myscript.sh: command not found


marked as duplicate by slm, jasonwryan, daisy, Anthon, manatwork Nov 1 '13 at 7:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    PATH is not inherited in sudo. Doing so would be a security flaw since someone might stick something unsafe in PATH such as .. – jordanm Oct 31 '13 at 20:32

Sudo resets PATH, along with many other environment variables, for security reasons. It doesn't matter what is set in /etc/profile, unless you run sudo -i.

The sudo manual page, under SECURITY NOTES, gives an insight about the security implications, along with the options you have to fiddle in your /etc/sudoers file to modify these restrictions, after you understand the implications of doing so."

Source: https://serverfault.com/questions/11899/how-to-override-a-path-environment-variable-in-sudo

Not the answer you're looking for? Browse other questions tagged or ask your own question.