Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've just installed a new program (let's call it foo) on my Linux machine. The program's files are in an unusual location that is not currently part of my $PATH. If I would like to be able to easily run this program from terminal, while in any directory, is it better to change my $PATH variable or to create an alias? Does it matter?

For example, the alias method would be adding this: alias foo="/path/to/program/"

And the $PATH method would be: export PATH=/path/to/program;$PATH

Which is better and why?

share|improve this question
up vote 2 down vote accepted

"Better" is a somewhat nebulous term, but I'd recommend adding the program's directory to $PATH, because (unlike aliases) that will be inherited by subprocesses of your shell.

For example, if you start an editor from your shell and then want to run from within the editor, as for example to compile the file you're editing or transform its text, then the editor will know where to find; if you instead add an alias, you'd need to specify the full path to when running it from the editor.

share|improve this answer

There is a third option. Create a link from one of the directories in $PATH to the program. A new directory can be dedicated just for this purpose (to link to programs in non standard locations). This way PATH will not be polluted if there are more programs like this added in the future and also Aaron mentions, it won't depend on the alias where the alias is not available.

share|improve this answer

Absolute path (Here your alias) is more and more faster than set PATH variable..

Because when you set PATH variable for example "/path/to/program" and you want to execute shell look at PATH variable and then search in that directory (/path/to/program) but when you use absolute path (Here your foo variable), shell won't look at path and then search that directory (/path/to/program) to find "".

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .