How to make `sudo` preserve $PATH?

You can always do:

sudo env "PATH=$PATH" godi_console

As a security measure on Debian, /etc/sudoers has the secure_path option set to a safe value.

Note that:

sudo "PATH=$PATH" godi_console

Where sudo treats leading arguments containing = characters as environment variable assignments by itself, would also work at running godi_console with your $PATH (as opposed to the secure_path) in its environment, but would not affect sudo's search path for executable, so wouldn't help sudo in finding that godi_console.


You can also set the default PATH at /etc/sudoers

edit the file using visudo

and update the line to what ever you wish: Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin


SUDO is doing env variables reset by default.

Check out its manual and option called env_reset.

You just need to disable it in /etc/sudoers.

Tags:

Path

Sudo