I have a program that is installed in a custom directory under /opt. To make it easier to run it, I edited my bashrc to add said directory to my path:
export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin
This works fine if I want to run the program without sudo. However, if I try to run it with sudo it fails with a "command not found" error.
$ sudo godi_console
sudo: godi_console: command not found
Inspecting the PATH variable after using sudo reveals that its not including the same PATH I have as a normal user:
$ sudo sh
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Why is the PATH not the same? Am I doing something wrong? I'm on Debian Jessie, if it makes a difference.
One thing I tried was to invoke /opt/godi/sbin/godi_console directly, passing the absolute path to the executable. Unfortunatelly, that didn't help in this particular case because godi_console itself depends on the PATH being correctly set.
sudo -E godi_console
.-E
means "preserve environment".secure_path
and/or env_reset are configured like is the case in manysudo
deployments like on Debian.su
notsudo
, is unix.stackexchange.com/questions/460478 .