My question is related to another open question. My echo $PATH gives me an output which is like
/home/sahil/.rvm/gems/ruby-1.9.3-p125/bin:/home/sahil/.rvm/gems/ruby-1.9.3-p125@global/bin:/home/sahil/.rvm/rubies/ruby-1.9.3-p125/bin:/home/sahil/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/sahil/.rvm/bin{}:/home/android-sdks/{}:/home/android-sdks/platform-tools/{}:/home/android-sdks/tools/{}:/home/sahil/android-sdks/tools{}:/home/sahil/android-sdks/tools:/home/sahil/android-sdks/platform-tools/But running
ifconfig gives me an output like
Command 'ifconfig' is available in '/sbin/ifconfig'
The command could not be located because '/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with your user account.
ifconfig: command not foundafter running command like given in other question
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"it runs ifconfig but blocks other commands of ruby rails or rvm.
Seeking help how to resolve this. Also why this happens?
35 Answers
Try the command below
export PATH=$PATH:/usr/sbinOR (if you want to set all the paths)
export PATH=$PATH:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/bin:/usr/games 4 Your original $PATH (the line you posted is not very readible):
/home/sahil/.rvm/gems/ruby-1.9.3-p125/bin:
/home/sahil/.rvm/gems/ruby-1.9.3-p125@global/bin:
/home/sahil/.rvm/rubies/ruby-1.9.3-p125/bin:/home/sahil/.rvm/bin:
/usr/local/bin:/usr/bin:/bin:/usr/games:
/home/sahil/.rvm/bin{}:
/home/android-sdks/{}:
/home/android-sdks/platform-tools/{}:
/home/android-sdks/tools/{}:
/home/sahil/android-sdks/tools{}:
/home/sahil/android-sdks/tools:
/home/sahil/android-sdks/platform-tools/You have /usr/local/bin, /usr/bin and /bin. As you already found out ifconfig is inside /sbin.
So where that path is set you also need to include /sbin.
See rubygems docs on how to do this.
1/sbin is normally part of path. Other distros like fedora dont have it in PATH for normal users but I think Ubuntu always does. I will suggest you check your /etc/environment file and see if it is valid and has /sbin added to path. When I run cat /etc/environment, I get following output:
adnan@adnan-laptop:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"As you can see /sbin is already part of PATH environment variable. If your file has the same contents then check its permissions otherwise add /sbin to PATH in this file. For me the permissions are:
adnan@adnan-laptop:~$ ls -l /etc/environment
-rw-r--r-- 1 root root 79 2009-10-29 01:55 /etc/environment 2 You could easily solve this by adding /sbin to $PATH. The more important point is that, you should not have /sbin in the path by default.
See this page for a description of why:/sbin directory definition
/sbin contains system utilities that should be run by root or using sudo authority. So if you want to see your network configuration simply type:
sudo /sbin/ifconfigYou will be prompted for your password and then ifconfig will run.
What is the PATHvariable?
PATH is a list of directory paths. When the user types a command without providing the full path, this list is checked to see whether it contains a path that leads to the command. The order of paths in this variable indicates the order in which the command will be searched, in case there is a program by the same name in multiple directories the one located in the folder closest to the beginning of the list (left side) will be executed.
The reason why you got other commands blocked (from ruby rails and rvm) is because you executed this:
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"resulting in a PATH that does not contain the folders of such programs, namely:
/home/sahil/.rvm/gems/ruby-1.9.3-p125/bin:/home/sahil/.rvm/gems/ruby-1.9.3-p125@global/bin:/home/sahil/.rvm/rubies/ruby-1.9.3-p125/bin:/home/sahil/.rvm/binWhat you should do instead is add /sbin to you own PATH.
How to add /sbin to PATH
As the PATH is basically always in the environment you don't need to export it, you just need to add the /sbin directory to it. In order to do that you can execute in your bash
PATH="$PATH:/sbin"your path now should look something like this:
/home/sahil/.rvm/gems/ruby-1.9.3-p125/bin:/home/sahil/.rvm/gems/ruby-1.9.3-p125@global/bin:/home/sahil/.rvm/rubies/ruby-1.9.3-p125/bin:/home/sahil/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/sahil/.rvm/bin{}:/home/android-sdks/{}:/home/android-sdks/platform-tools/{}:/home/android-sdks/tools/{}:/home/sahil/android-sdks/tools{}:/home/sahil/android-sdks/tools:/home/sahil/android-sdks/platform-tools/:/sbinThis change will not be permanent though, once your close your current session PATH will be reloaded with the previous value. In order to make it permanent you should add this change to your ~/.profile file. One way of doing it is the following:
echo 'PATH="$PATH:/sbin"' >> ~/.profileNow you just need to execute the content of "~/.profile" in the current shell.
source ~/.profileYou are ready to go, not only your current shell but all your future sessions will have the PATH containing the directory.
Why did i use ~/.profile instead of ~/.bashrc?
This concept can be useful for you:
~/.profileis the place to put stuff that applies to your whole session, such as programs that you want to start when you log in (but not graphical programs, they go into a different file), and
environment variable definitions.
~/.bashrcis the place to put stuff that applies only to bash itself, such as alias and function definitions, shell options, and prompt settings. (You could also put key bindings there, but for bash they normally go into ~/.inputrc.)
You cant get more information about this topic here.
Should you have /sbin in your PATH?
I'm not going to discuss here if /sbin should or should not be in PATH by default because that can turn out to be not a very productive discussion to be had here. I have it, you can have it if you want. Your call.