Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 compiled the last emacs version from the source code (v24.2) because the version installed on my machine is (quite) old for me (v21.3). I've done the usual:

$configure --prefix=$HOME
make install

Now I am testing emacs and realized that it still launches the previous version ... while my $HOME/bin path is supposed to override the system one (since it is prepended to $PATH in my .bashrc file).

My first thought was to see the which command output. And surprise, it gives the path to the new emacs. I can't understand where is the discrepancy here. In the same session here is the different outputs:

$ emacs --version
GNU Emacs 21.3.1

$ `which emacs` --version
GNU Emacs 24.2.1

I have no alias involving emacs. At all.

$ alias | grep emacs

Any idea what is going on please?

share|improve this question
what does which emacs return? – Ulrich Dangel Sep 6 '12 at 16:19
up vote 10 down vote accepted

The three possibilities that come to mind for me:

  • An alias exists for emacs (which you've checked)
  • A function exists for emacs
  • The new emacs binary is not in your shell's PATH hashtable.

You can check if you have a function emacs:

bash-3.2$ declare -F | fgrep emacs
declare -f emacs

And remove it:

unset -f emacs

Your shell also has a PATH hashtable which contains a reference to each binary in your PATH. If you add a new binary with the same name as an existing one elsewhere in your PATH, the shell needs to be informed by updating the hashtable:

hash -r

Additional explanation:

which doesn't know about functions, as it is not a bash builtin:

bash-3.2$ emacs() { echo 'no emacs for you'; }
bash-3.2$ emacs
no emacs for you
bash-3.2$ which emacs
bash-3.2$ `which emacs` --version | head -1
GNU Emacs 22.1.1

New binary hashtable behaviour is demonstrated by this script.

bash-3.2$ PATH=$HOME/bin:$PATH
bash-3.2$ cd $HOME/bin

bash-3.2$ cat nofile
cat: nofile: No such file or directory
bash-3.2$ echo echo hi > cat
bash-3.2$ chmod +x cat
bash-3.2$ cat nofile
cat: nofile: No such file or directory

bash-3.2$ hash -r
bash-3.2$ cat nofile
bash-3.2$ rm cat
bash-3.2$ cat nofile
bash: /Users/mrb/bin/cat: No such file or directory

bash-3.2$ hash -r
bash-3.2$ cat nofile
cat: nofile: No such file or directory

Although I didn't call it, which cat would always return the first cat in my PATH, because it doesn't use the shell's hashtable.

share|improve this answer
While there is good information here, it misses out on the type command. – jordanm Sep 6 '12 at 22:06

Yes, don't use which:

  • On some systems, it's an external command implemented as a csh script, which may read a configuration that changes the PATH.
  • There's a builtin for that. Two, even: type and command. The POSIX way:

    command -v emacs       # machine-readable format
    type emacs             # human-only format

    In bash, you can also use type -p emacs to see just the path of an external command.

However, here, which is actually right. Bash keeps information about the location of a command in memory, so that it can execute the command faster the next time. You've installed a new emacs executable on your PATH, but bash still has the old location in its cache. Run hash emacs to look up emacs again, or hash -r to empty the cache.

share|improve this answer

Did you logout and login to cause your updated .bashrc login file to be re-read? If not, your current session's environment hasn't been updated.

share|improve this answer
If that were the case, `which emacs` --version would agree with emacs --version, because which inherits its PATH from the current shell. – mrb Sep 6 '12 at 19:22
@mrb : Point well taken. – JRFerguson Sep 6 '12 at 19:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.