2

I have seen the thread How to add a directory to the PATH?

I already have added the directory in my PATH by directly editing the /etc/environment. However, I do not get the command working when I use it as

$ sudo command --options

However, things work great when I do

# command --options

or

$ command --options

Why is this the case? Also, this is not my full question. I would be thankful if someone could explain the various ways of adding directories to the path, how they work, and when is each of them in effect. How are they different?

The point of the question is not so much to get things working, but to understand how it all works. Pointing to a guide that explains this would be a great answer too.

3
  • Have you executed the environment file using source? Feb 16 '12 at 18:59
  • No. What does that mean exactly, and what is it supposed to do?
    – ste_kwr
    Feb 16 '12 at 19:29
  • 1
    If you modify a file that contains such environment variables and you want that change to kick in, you have to execute the modified file like so, source FILE. Feb 16 '12 at 19:34
2

Add it to /root/.bashrc, /etc/profile, and /etc/bash.bashrc. It should work :)

The reason is that sudo uses the /root files, and not the system-wide files (or at least, in my experience).

7
  • how do you do this in ubuntu 12.04
    – John
    Aug 1 '13 at 0:28
  • @John it doesn't work?
    – MiJyn
    Aug 1 '13 at 4:08
  • no, i add the path to the directory the script is in to each file, and try to run it with sudo all i get is sudo: hello: command not found. i use the explicit path to the file.
    – John
    Aug 1 '13 at 7:28
  • @John don't use the explicit path to the file, use the parent folder. I.e. instead of specifying "/home/john/bin/hello", use "/home/john/bin/"
    – MiJyn
    Aug 1 '13 at 21:24
  • when i said file i should have said directory the file is in, or parent forlder. but that is what i do example: export PATH=${PATH}:/home/john/bin/
    – John
    Aug 1 '13 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.