This article explains how set your PATH variable under Linux. This has the same use as that of setting the PATH variable under DOS. Under Linux too, modifying the PATH would add these new directories to your default search path.
So in case you have a particular executable in a particular directory, then if you add that directory to your PATH, then you would only have to type the name of the executable at the prompt rather than then absolute path for that executable. Got it?? Read the example below to figure out what exactly I am speaking about..
Suppose you have a program by the name 'tetris' in a folder called /usr/local/games . So in order to run this program you would have to type the following at the prompt
The above command would execute your program. But typing this every time you want to play this wonderful game makes it slightly cumbersome. It would be much better if you could only type 'tetris'.
A solution would be to add the /usr/local/games directory to your PATH, so that next time onwards you would only have to type 'tetris' at the prompt rather than the absolute path.
To add this directory to your PATH you have to edit a file called 'bash_profile' that would be present in your Home directory (in Redhat Linux 6.2). So if there is a user by the name David then this file would mostly be found at /home/David/.bash_profile
Note : The period (.) before the name of the file. This period make this file a hidden file. So remember to view hidden files also while seeing a directory listing (This option would be in some menu in X , at the prompt simply use 'ls -a' to see hidden files).
This file would be having a particular line starting with the string PATH. For e.g. the file that I have on my machine has a line such as
To add the directory /usr/local/games to this I would have to modify this line as follows
Once you have modified this file, save it and then execute it as follows
Note : To execute this script basically at the $ prompt type a period ' . ' leave a space and then type $HOME/ Once this is done press <Tab> key. Doing so would replace what ever you have typed with the path to your home directory. Once this happens all you have to do is append a .bash_profile to what is already present at the prompt and finally press <Enter>
On executing the script you wouldn't see any messages at the output, but then onwards you could simply type 'tetris' at the prompt to execute the program /usr/local/games/tetris
So now you are on the right PATH ;-)
View more threads in the same category: