Open homebrew version of emacs instead of Apple version

I installed emacs 26.1 via brew install emacs, but when I try to start emacs via command line, only the outdated Apple-supplied version (22.1.1) opens.

However, emacs is apparently correctly linked:

$ which -a emacs
/usr/local/bin/emacs
/usr/bin/emacs

$ exa -l /usr/local/bin/emacs
lrwxr-xr-x 32 $USER 26 Aug 22:42 /usr/local/bin/emacs -> ../Cellar/emacs/26.1_1/bin/emacs

$ exa -l /usr/local/Cellar/emacs/26.1_1/bin/emacs
lrwxr-xr-x 10 $USER 25 May 18:41 /usr/local/Cellar/emacs/26.1_1/bin/emacs -> emacs-26.1

PATH also has /usr/local/bin before /usr/bin, so why does emacs still open /usr/bin/emacs?


Solution 1:

The problem was that emacs was still hashed, so the old version was used even after installing the new one. Therefore,

$ type emacs
emacs is hashed (/usr/bin/emacs)

This can be remedied by either logging out and then back in again, or forcing the shell to rehash by running hashemacs, which will result in

$ type emacs
emacs is hashed (/usr/local/bin/emacs)

Then, the correct version will be used.