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 come from using cygwin on Windows, and I just started using a mac. I'm wondering why it seems that search paths don't work like they should.

If I have a program in /usr/bin/prog and I delete it. It seems to keep trying that exact path instead of searching for it again (let's say I move it to /usr/local/bin).

Is this due to the terminal app or is it something specific to mac? Also, if I want to install a new version of python into /usr/local/bin, is the right way to do it to remove it from /usr/bin/?

share|improve this question

migrated from Jun 23 '11 at 18:54

This question came from our site for professional and enthusiast programmers.

You don't say which shell you're using, though your question is tagged with bash. The default Mac OS X shell is tcsh, which If you're using tcsh or csh, they cache a table of items on your path. In order to refresh the table, issue the rehash command at the shell prompt.

You'll need to do this whenever you move or delete an executable, or if you add something to your path.

If you're really using the bash shell then this doesn't apply.

share|improve this answer
The Mac Os X default shell isn't tsch it's bash. (It used to be back in 10.2.x) It changed after 10.3.x – Slomojo Jun 23 '11 at 3:40
Ooooops... I thought of that later. I changed my default shell to tcsh so long ago I forgot. However, the behavior that verhogen is seeing is neatly explained by the tcsh/csh behavior that I jumped to that conclusion – Eric Jun 23 '11 at 12:16

OS X terminal will try the paths declared in your PATH variable, in order, until it finds it or runs out of places to check. You can check what your PATH variable is by typing the following at the command prompt:

echo $PATH

You can run the following from the command prompt to view where your shell is finding the program in question:

which prog

If you want to upgrade python, I recommend installing it to the same location as it already exists. If you want to have more than one version installed to your machine at a time, then installing it in /usr/local/bin would be a logical choice IMO.

share|improve this answer
That's what should happen, but if you run git, and then delete it from usr/bin, it doesn't seem to search again. It just keeps trying to run /usr/bin/git. – vonhogen Jun 22 '11 at 22:19
Try in a new shell to check it hasn't been cached. You can also use printenv to check if there's anything weird going on with your environment – Jim Jun 22 '11 at 22:24

From what I understand when you execute a program it will search the folders on your $PATH variable, which is separated by ":" eg.


Is your $PATH set up correctly? To find this out use:

echo $PATH

You can also use which python to find which version and from where it is running. I believe this is also a left to right search so it will take the first program named python it finds on the path.

share|improve this answer

Instead of using

which prog

you may use the Bash builtin

type -P prog

# some examples using: type -P cmd
$(type -P prog) arg1 arg2 arg3 ...
myls=$(type -P ls) && $myls -l

For more information see

help type

# The -P flag forces a PATH search for each NAME, even if it is an alias,
# builtin, or function, and returns the name of the disk file that would
# be executed.

Yet another option might be to try

help command
command -p prog


share|improve this answer

You must log in to answer this question.

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