Skip to main content
Improved the english.
Source Link
hugomg
  • 6.1k
  • 5
  • 43
  • 55

I need to runhave a program that is installed onin a custom directory under /opt/godi/sbin (a custom directory). IfTo make it easier to run it, I edited my bashrc to add thatsaid directory to my PATH, by adding the following line to my .bashrc filepath:

export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin

thenThis works fine if I can trywant to run the command just fine (except that it fails because it needsprogram without sudo). However, whenif I try to userun it with sudo: it fails with a "command not found" error.

$ sudo godi_console

I get the following error

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 and unfortunately, if it makes a difference.

One thing I cannot get around the issue bytried was to invoke /opt/godi/sbin/godi_console directly, passing sudo the the absolute linkpath to godi_consolethe executable. Unfortunatelly, that didn't help in this particular case because godi_console itself also depends on the PATH being correctly set.

I need to run a program installed on /opt/godi/sbin (a custom directory). If I add that directory to my PATH, by adding the following line to my .bashrc file

export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin

then I can try to run the command just fine (except that it fails because it needs sudo). However, when I try to use sudo:

sudo godi_console

I get the following error

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 and unfortunately I cannot get around the issue by passing sudo the the absolute link to godi_console because godi_console itself also depends on the PATH being correctly set.

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.

Better title
Link
user
  • 30k
  • 17
  • 82
  • 147

Cannot run a command with sudo How to make `sudo` preserve $PATH?

Source Link
hugomg
  • 6.1k
  • 5
  • 43
  • 55

Cannot run a command with sudo

I need to run a program installed on /opt/godi/sbin (a custom directory). If I add that directory to my PATH, by adding the following line to my .bashrc file

export PATH=$PATH:/opt/godi/bin:/opt/godi/sbin

then I can try to run the command just fine (except that it fails because it needs sudo). However, when I try to use sudo:

sudo godi_console

I get the following error

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 and unfortunately I cannot get around the issue by passing sudo the the absolute link to godi_console because godi_console itself also depends on the PATH being correctly set.