I just installed go to /usr/local/go, and in ~/.bashrc added this line:

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

Now go works from the command line, but sudo go gives me:

$ sudo go
sudo: go: command not found
$ sudo echo $PATH
  • Can you post the output of sudo echo $PATH Apr 2, 2012 at 17:36

3 Answers 3


sudo command has env_keep and env_reset parameters in sudoers file.

You have to either edit your env_keep setting or use sudo -E.

  • 2
    On my Debian-9 system sudo -E does not keep the $PATH variable.
    – Ark-kun
    Aug 29, 2018 at 3:32

Edit the file /etc/sudoers. Add the desired paths to the following line:

Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin


Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin


Check if you've security policy setup for your PATH by the following command:

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

If so, either disable it or add it there by sudo visudo.

See: Why are PATH variables different when running via sudo and su? at Unix SE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .