0

If I put a new path into my $PATH variable like so:

PATH=$PATH:$HOME/pear/bin/

I can then access the programs in my pear bin. Works as expected, but while I can do this:

phpunit -version

phpunit being a program that resides in my pear bin, I cannot do this:

sudo phpunit -version

as I get the following error:

sudo: phpunit: command not found

does the sudo command not have universal access?

2 Answers 2

2

The -E option to sudo preserves environment variables, otherwise they are largely discarded. So, the following should work:

sudo -E phpunit -version
4
  • No, same error appears when above command is used Mar 24, 2013 at 14:01
  • @Kevin Bradshaw: and yet this is the *correct*(!) answer. Please read man sudoers to find out what affects -E. Mar 25, 2013 at 1:36
  • 1
    @0xC0000022L It may indeed be the "correct" answer, but it did not work, whereas the answer I accepted worked exactly as I wanted. The only criteria that I have for accepting an answer is whether or not it works. The fact that I asked the question means I know little about it, so I am hardly in a position to grade the quality of the answers that dont work for me. That said, I am grateful the the poster for taking the time to help. Mar 25, 2013 at 9:24
  • @KevinBradshaw: a fair point, I get it. And this answer could have been a lot better. E.g. pointing out what -E does, because that requires a little more configuration work in the sudoers file. Mar 26, 2013 at 20:41
1

I'm not sure about this , but try it.

Maybe you must add the same PATH PATH=$PATH:$HOME/pear/bin/ to the root's PATH variable.

sudo -i
echo $PATH

to see the PATH directories for root.

Then as you are in root account do

ls -a

and you will see .bashrc and .profile files for root account.

Add the line PATH=$PATH:$HOME/pear/bin/ to the appropriate file.

1
  • I tried this, and now sudo claims to have the env variable. But apps launched by it still fail for lack of the env variable. Feb 2, 2014 at 6:09

You must log in to answer this question.

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