04 under WSL. I have binary of pyenv in my PATH even with sudo's PATH, but i cannot run it with sudo for some reason.
test@pc:~$ which pyenv /home/test/.pyenv/bin/pyenv test@pc:~$ sudo which pyenv test@pc:~$ sudo echo $PATH | perl -p -e 's/:/\n/g' | grep pyenv /home/test/.pyenv/plugins/pyenv-virtualenv/shims /home/test/.pyenv/shims /home/test/.pyenv/bin I tried to
sudo -i sudo -E with pyenv and it doesnt works. Without sudo it works fine but i cannot install python because of permissions. What im doing wrong?
1 Answer
For security reasons, sudo locates programs using its own secure_path, defined in the /etc/sudoers/ file:
Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" Also note that when you do sudo echo $PATH, the $PATH variable is expanded by the user's shell before being passed to sudo. To see root's path using sudo, you would need to do something like sudo bash -c 'echo $PATH'