与sudo一起使用时找不到某些程序


9

我刚装/usr/local/go,并在~/.bashrc加入这一行:

export PATH=$PATH:/usr/local/go/bin

现在go可以从命令行运行,但是可以sudo go给我:

$ sudo go
sudo: go: command not found
~
$ sudo echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/benjamin/algs4/bin:/usr/local/go/bin

您可以将sudo echo $PATH
Manish Sinha

Answers:



3

编辑文件/ etc / sudoers。将所需的路径添加到以下行:

默认值secure_path = / sbin:/ bin:/ usr / sbin:/ usr / bin

例:

默认值secure_path = / sbin:/ bin:/ usr / sbin:/ usr / bin:/ usr / local / sbin:/ usr / local / bin


0

通过以下命令检查您是否为PATH设置了安全策略:

$ sudo sudo -V | grep PATH
Value to override user's $PATH with: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

如果是这样,请禁用它或在那里添加它sudo visudo

请参阅:通过sudo和su运行时,为什么PATH变量不同?在Unix SE

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.