How to Override a PATH Environment Variable in Sudo

environment-variablesrootsudo

I set PATH in /etc/profile. I do not have any problems in the case of the general user, but PATH does not go when I become the root authority in sudo.

What would you do to override the PATH which is set by /etc/profile even if I become the root authority in sudo?

Best Answer

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.