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 thought I understood this, but I'm getting unexplained behavior. I have these files:

$ which -a kvm | xargs ls -l
lrwxrwxrwx 1 root root 18 2011-11-17 17:14 /usr/bin/kvm -> qemu-system-x86_64
lrwxrwxrwx 1 root root 18 2011-11-17 17:21 /usr/local/bin/kvm -> qemu-system-x86_64
$ which -a qemu-system-x86_64 | xargs ls -l
-rwxr-xr-x 1 root root 2535168 2011-10-04 02:44 /usr/bin/qemu-system-x86_64
-rwxr-xr-x 1 root root 3497304 2011-11-17 16:26 /usr/local/bin/qemu-system-x86_64

And they are different versions:

$ /usr/bin/kvm --version
QEMU PC emulator version 0.12.3 (qemu-kvm-0.12.3), Copyright (c) 2003-2008 Fabrice Bellard
$ /usr/local/bin/kvm --version
QEMU emulator version 0.15.92 (qemu-kvm-devel), Copyright (c) 2003-2008 Fabrice Bellard

My path has /usr/local/bin first, and when I do which I see that one. So I'd expect it to win. But instead the older version wins:

$ echo $PATH
$ which kvm
$ kvm --version
QEMU PC emulator version 0.12.3 (qemu-kvm-0.12.3), Copyright (c) 2003-2008 Fabrice Bellard

Why does kvm --version give me 0.12 instead of 0.15???

share|improve this question
up vote 7 down vote accepted

Linux does not make the decision in this case; it's supplied with the exact path by your shell. When using advanced shells such as bash or zsh, the which tool is inaccurate since it only checks $PATH, but there are several more possibilities. Running type kvm should tell you where the shell is looking for it.

  • "hashed": The first time you run a command, the bash shell remembers its location so that it won't have to search the entire $PATH again. The remembered locations are only kept in memory. Use hash to list them and hash -r to reset, or simply start a second shell window.

  • "alias": You may have created an alias "kvm" pointing to the old path. If this is the case, use unalias kvm to remove the alias.

  • "function": Similar to aliases, but more expressive. Again, it's possible that you have added and forgotten a function named kvm pointing to the wrong path. Use unset kvm to remove such a function.

share|improve this answer

You can override the PATH search by declaring an alias

alias kvm=/sbin/kvm

Try type -a kvm

I created an alias for date

$ which -a date

$ type -a date
date is aliased to `/bin/date'
date is /usr/local/bin/date
date is /bin/date
share|improve this answer

You must log in to answer this question.

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