Reputation: 831
Ubuntu 10.04.4 LTS
I have seen the posts regarding sudo and PATH on various sites including stackoverflow. I think this is different, so I'm pretty sure it is not a duplicate (but I'm not sure).
1) First, the non-sudo path to ruby:
$ which ruby
/usr/local/ruby/bin/ruby
2) and then the sudo path to ruby:
$ sudo which ruby
/usr/bin/ruby
Ok, so far so good. The path changed when I used sudo.
3) But here's the part I don't get:
$ sudo echo $PATH
/home/cm6/bin:/usr/local/ruby/bin:/usr/local/ruby/bin:/usr/local/sbin:<snipped>
ie, the path to ruby is in the $PATH variable set when I use sudo.
4) And a little stranger again:
$ echo $PATH
/home/cm6/bin:/usr/local/ruby/bin:/usr/local/ruby/bin:/usr/local/sbin:<snipped>
This time, no sudo, but the $PATH variable content is the same as that for sudo.
Given $PATH variable is the same with or without sudo, why did the "which ruby" give me different answers? It's as if the $PATH variable doesn't hold the real PATH under sudo.
So, finally, my question: how do I get the real/accurate/correct PATH used by sudo?
Thanks,
John
Upvotes: 1
Views: 317
Reputation: 11389
sudo echo $PATH
evals $PATH before calling sudo.
to find out for sure:
sudo -s
echo $PATH
You need to add the PATH variable to env_keep in /etc/sudoers
Upvotes: 1