Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have seen the thread How to add a directory to my 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.

share|improve this question
    
Have you executed the environment file using source? –  Octavian Damiean 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. –  Octavian Damiean Feb 16 '12 at 19:34

1 Answer 1

up vote 2 down vote accepted

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).

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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