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.

ste_kwr
  • 11,210

1 Answers1

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

MiJyn
  • 3,336
  • how do you do this in ubuntu 12.04 – John Aug 01 '13 at 00:28
  • @John it doesn't work? – MiJyn Aug 01 '13 at 04: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 01 '13 at 07: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 01 '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 01 '13 at 21:40
  • i even added it to /root/.profile – John Aug 01 '13 at 21:42
  • oh okay, hmm... so it works if you don't run it with sudo? – MiJyn Aug 01 '13 at 21:44