Why does sudo change the PATH? [closed]

This is an annoying function a feature of sudo on many distributions.

To work around this “problem” on ubuntu I do
the following in my ~/.bashrc

alias sudo='sudo env PATH=$PATH'

Note the above will work for commands that don’t reset the $PATH themselves.
However `su’ resets it’s $PATH so you must use -p to tell it not to. I.E.:

sudo su -p

Leave a Comment