7

New at programming here. I couldn't find this when I searched Google and SO, but I was wondering what programmers mean when they say "put X in your path." Is this the usr/bin?

Any other resources I can read up on to understand this?

1

5 Answers 5

11

They usually mean to

  • put your script or executable in one of the directories listed in the PATH environment variable, as shown by echo $PATH.

  • or modify said variable to contain the directory where you script/program/application is

The PATH variable contains a list of colon (:) separated directories to be searched for programs to execute. For example:

$ echo $PATH
/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/games

You could put your program in e.g. /usr/local/bin, so that it will be detected by other programs without you having to explicitly tell them to look at e.g. /home/user/apps/MyApp.

Alternatively, you could modify that variable to contain /home/user/apps/MyApp. For a single bash shell session, this would do:

$ export PATH="$PATH":/home/user/apps/MyApp

To do it permanently for bash you have to enter this line (without the $ shell prompt) in ~/.bashrc or ~/.bash_profile (or both).

If you have another shell (bash is the default for most Linux distributions) the commands above should be changed accordingly.

2

Well, here is a link by LINFO (The Linux Information Project) : http://www.linfo.org/path_env_var.html

It explains to you what it is, how you get it, how you change it, well, everything you need to know about it :)

1
  • +1 for the new (unregistered?) superuser user! Hope the transition will go fine. Dec 14, 2010 at 14:10
1

When executing a program from the command line, the shell look in many directories to find the program. The list of directory to lookup is defined in a variable named PATH. You can print the content with echo %PATH% on Windows and echo $PATH on Linux and other Unix derived OS.

So when you see path X in you path, it means that you can copy X into one of the directory listed in that variable, or you can change the PATH variable to contains the directory where X is located.

1

Path is the name of an environment variable in an operating system. Linux, Unix, DOS, Windows and other operating systems have this concept. The Path environment variable defines the folders to be searched for a command or application to be executed. Hence, if X is the folder which contains your command or application, by adding X to your Path, it allows command, scripts or applications in X folder to be executed by just typing its name alone.

Try this "echo $PATH"

To add X (e.g. /home/x) to $PATH, type

PATH=$PATH:/home/x

In Linux or Unix, folders are separated by colon (:) while in Dos, Windows, etc, folders are separated by semi-colons (;)

http://lowfatlinux.com/linux-environment-variables.html

1
  • 1
    It also depends on your shell. For BASH use 'export PATH=$PATH:/home/x' - if you don't do this then the PATH is not propogated to any other shells. For CSH 'setenv PATH $PATH:/home/y' (you may need to escape ':' as '\:'
    – DanS
    Dec 14, 2010 at 14:18
0

The path is a colon-delimited list of directories that contain executables and libraries. When you run a program, for example bash, all the directories in the path get checked for a program named bash. In my case, it's inside /bin.

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/diet/bin
$

You must log in to answer this question.