I'm sure most people are aware the 'sudo' command sterilizes the user's environment variables before executing the command passed to it. The most common issue I've run into with this is $PATH not being preserved. The usual scenario is that I have an application installed into /opt and I've appended it's location to $PATH, which works just fine until you try to execute the application with 'sudo' and it fails because the command is no longer in the current path.
The fix to this is really straight forward and I'm surprised I hadn't thought of it earlier. Simply add the following to your $HOME/.bashrc file.
alias sudo="sudo env PATH=$PATH"What this does is use 'sudo' to run 'env' which is passed the provided command but sets the target environment's PATH to match the current users before executing it.
Don't forget that you can always run the unaliased version of a command simply by prefixing it with a backslash.